2012-10-10 21:37:42 +00:00
|
|
|
|
2012-10-18 09:19:50 +00:00
|
|
|
module Set (empty,singleton,insert,remove
|
|
|
|
,member
|
2012-10-19 07:13:28 +00:00
|
|
|
,foldl,foldr,map
|
2012-10-18 09:19:50 +00:00
|
|
|
,union,intersect,diff
|
|
|
|
,toList,fromList
|
|
|
|
) where
|
2012-10-10 21:37:42 +00:00
|
|
|
|
2013-02-22 23:19:40 +00:00
|
|
|
import Dict as Dict
|
|
|
|
|
2013-02-08 04:23:25 +00:00
|
|
|
type Set t = Dict t ()
|
|
|
|
|
|
|
|
empty : Set t
|
2012-10-16 06:03:14 +00:00
|
|
|
empty = Dict.empty
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
singleton : t -> Set t
|
2012-10-16 06:03:14 +00:00
|
|
|
singleton k = Dict.singleton k ()
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
insert : t -> Set t -> Set t
|
2012-10-16 06:03:14 +00:00
|
|
|
insert k = Dict.insert k ()
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
remove : t -> Set t -> Set t
|
2012-10-16 06:03:14 +00:00
|
|
|
remove = Dict.remove
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
member : t -> Set t -> Bool
|
2012-10-16 06:03:14 +00:00
|
|
|
member = Dict.member
|
2012-10-18 09:19:50 +00:00
|
|
|
|
2013-02-08 04:23:25 +00:00
|
|
|
union : Set t -> Set t -> Set t
|
2012-10-18 09:19:50 +00:00
|
|
|
union = Dict.union
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
intersect : Set t -> Set t -> Set t
|
2012-10-18 09:19:50 +00:00
|
|
|
intersect = Dict.intersect
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
diff : Set t -> Set t -> Set t
|
2012-10-18 09:19:50 +00:00
|
|
|
diff = Dict.diff
|
|
|
|
|
2013-02-08 04:23:25 +00:00
|
|
|
toList : Set t -> [t]
|
2012-10-18 09:19:50 +00:00
|
|
|
toList = Dict.keys
|
2013-02-08 04:23:25 +00:00
|
|
|
|
|
|
|
fromList : [t] -> Set t
|
2012-10-18 09:19:50 +00:00
|
|
|
fromList = List.foldl (\k t -> Dict.insert k () t) empty
|
|
|
|
|
2013-02-08 04:23:25 +00:00
|
|
|
foldl : (a -> b -> b) -> b -> Set a -> b
|
|
|
|
foldl f = Dict.foldl (\k _ b -> f k b)
|
|
|
|
|
|
|
|
foldr : (a -> b -> b) -> b -> Set a -> b
|
|
|
|
foldr f = Dict.foldr (\k _ b -> f k b)
|
|
|
|
|
|
|
|
map : (a -> b) -> Set a -> Set b
|
|
|
|
map f = fromList . List.map f . toList
|