[clean up Relation and move it to Util
John Meacham <john@repetae.net>**20050923022110] move ./Relation.hs ./Util/Relation.hs
hunk ./FrontEnd/Exports.hs 21
-import Relation as R
+import Util.Relation as R
hunk ./Util/Relation.hs 1
-module Relation(module Relation, module Set) where
hunk ./Util/Relation.hs 2
+-- | extend Data.Set with relation operations
+
+module Util.Relation(module Util.Relation, module Set) where
+
hunk ./Util/Relation.hs 7
+import qualified Data.Set as Set (map)
hunk ./Util/Relation.hs 12
---domain :: Rel a b -> Set a
---range :: Rel a b -> Set b
+domain :: Ord a => Rel a b -> Set a
+domain r = mapMonotonic fst r
hunk ./Util/Relation.hs 15
-domain r = fromAscList (map fst (toAscList r))
-range r = fromList [ y | (_,y) <- toList r ]
+range :: (Ord a,Ord b) => Rel a b -> Set b
+range r = Set.map snd r
hunk ./Util/Relation.hs 18
+flipRelation :: (Ord a, Ord b) => Rel a b -> Rel b a
+flipRelation = Set.map (\ (x,y) -> (y,x))
hunk ./Util/Relation.hs 21
+restrictDomain :: (Ord a, Ord b) => (a -> Bool) -> Rel a b -> Rel a b
hunk ./Util/Relation.hs 23
+
+restrictRange :: (Ord a, Ord b) => (b -> Bool) -> Rel a b -> Rel a b
hunk ./Util/Relation.hs 28
-mapDomain f r = fromList [ (f x,y)| (x,y) <- toList r ]
-mapRange f r = fromList [ (x,f y)| (x,y) <- toList r ]
+mapDomain :: (Ord a, Ord b, Ord c) => (a -> c) -> Rel a b -> Rel c b
+mapDomain f r = Set.map (\ (x,y) -> (f x,y)) r
+
+mapRange :: (Ord a, Ord b, Ord c) => (b -> c) -> Rel a b -> Rel a c
+mapRange f r = Set.map (\ (x,y) -> (x,f y)) r
hunk ./Util/Relation.hs 35
+
hunk ./Util/Relation.hs 39
-applyRelation r a = map snd (toList $ restrictDomain (== a) r)
+applyRelation r a = Prelude.map snd (toList $ restrictDomain (== a) r)