7220N/ADescription : injective maps
7220N/ACopyright : (c) Uni Bremen 2006
7220N/AMaintainer : Christian.Maeder@dfki.de
7220N/A-- | the data type of injective maps
7220N/AunsafeConstructInjMap = InjMap
7220N/A-- | get an empty injective map
7220N/A{- | insert a pair into the given injective map. An existing key and the
7220N/Acorresponding content will be overridden. -}
7220N/Ainsert :: (Ord a, Ord b) => a -> b -> InjMap a b -> InjMap a b
7220N/Ainsert a b i = let InjMap m n = delete a b i in
7220N/A{- | delete the pair with the given key in the injective
7220N/Amap. Possibly two pairs may be deleted if the pair is not a member. -}
7220N/Adelete :: (Ord a, Ord b) => a -> b -> InjMap a b -> InjMap a b
deleteA :: (Ord a, Ord b) => a -> InjMap a b -> InjMap a b
-- | delete codomain entry
deleteB :: (Ord a, Ord b) => b -> InjMap a b -> InjMap a b
deleteB b = transpose . deleteA b . transpose
-- | check membership of an injective pair
member :: (Ord a, Ord b) => a -> b -> InjMap a b -> Bool
(Just x, Just y) | x == b && y == a -> True
-- | transpose to avoid duplicate code
transpose :: InjMap a b -> InjMap b a
transpose (InjMap m n) = InjMap n m
-- | look up the content at domain
lookupWithA :: (Ord a, Ord b) => a -> InjMap a b -> Maybe b
lookupWithA a (InjMap m n) = case
Map.lookup a m of
Just e -> if e == a then Just b
-- the errors indicate that the injectivity is destroyed
-- | look up the content at codomain
lookupWithB :: (Ord a, Ord b) => b -> InjMap a b -> Maybe a
lookupWithB y = lookupWithA y . transpose
-- | update codomain at domain value that must be defined
updateBWithA:: (Ord a, Ord b) => a -> b -> InjMap a b -> InjMap a b
updateBWithA a b m = case lookupWithA a m of
-- | update domain at codomain value that must be defined
updateAWithB :: (Ord a, Ord b) => b -> a -> InjMap a b -> InjMap a b
updateAWithB b newA = transpose . updateBWithA b newA . transpose