on master help sign in
Add type annotations to the Set library.
commita8850d62dfe437cb306595127455a108f5528a69 authorevancz <info@elm-lang.org> dateThu 7 Feb 2013, 20:23 (14 years ago) parentc02228f
1 file changed+27−3
core-elm/Set.elm+27−3
core-elm/Set.elm+27−3
@@ -6,19 +6,43 @@ module Set (empty,singleton,insert,remove
66 ,toList,fromList
77 ) where
88
9+type Set t = Dict t ()
10+
11+empty : Set t
912empty = Dict.empty
13+
14+singleton : t -> Set t
1015singleton k = Dict.singleton k ()
16+
17+insert : t -> Set t -> Set t
1118insert k = Dict.insert k ()
19+
20+remove : t -> Set t -> Set t
1221remove = Dict.remove
22+
23+member : t -> Set t -> Bool
1324member = Dict.member
1425
26+union : Set t -> Set t -> Set t
1527union = Dict.union
28+
29+intersect : Set t -> Set t -> Set t
1630intersect = Dict.intersect
31+
32+diff : Set t -> Set t -> Set t
1733diff = Dict.diff
1834
35+toList : Set t -> [t]
1936toList = Dict.keys
37+
38+fromList : [t] -> Set t
2039fromList = List.foldl (\k t -> Dict.insert k () t) empty
2140
22−foldl f = Dict.foldl (\k v b -> f k b)
23−foldr f = Dict.foldr (\k v b -> f k b)
24−map f t = fromList . List.map f $ toList t
41+foldl : (a -> b -> b) -> b -> Set a -> b
42+foldl f = Dict.foldl (\k _ b -> f k b)
43+
44+foldr : (a -> b -> b) -> b -> Set a -> b
45+foldr f = Dict.foldr (\k _ b -> f k b)
46+
47+map : (a -> b) -> Set a -> Set b
48+map f = fromList . List.map f . toList