on master help sign in
Add type annotations to the Set library.
a8850d6evancz
core-elm/Set.elm+27−3
@@ -6,19 +6,43 @@ module Set (empty,singleton,insert,remove
6 ,toList,fromList
6 ,toList,fromList
7 ) where
7 ) where
8
8
9+type Set t = Dict t ()
10+
11+empty : Set t
9empty = Dict.empty
12empty = Dict.empty
13+
14+singleton : t -> Set t
10singleton k = Dict.singleton k ()
15singleton k = Dict.singleton k ()
16+
17+insert : t -> Set t -> Set t
11insert k = Dict.insert k ()
18insert k = Dict.insert k ()
19+
20+remove : t -> Set t -> Set t
12remove = Dict.remove
21remove = Dict.remove
22+
23+member : t -> Set t -> Bool
13member = Dict.member
24member = Dict.member
14
25
26+union : Set t -> Set t -> Set t
15union = Dict.union
27union = Dict.union
28+
29+intersect : Set t -> Set t -> Set t
16intersect = Dict.intersect
30intersect = Dict.intersect
31+
32+diff : Set t -> Set t -> Set t
17diff = Dict.diff
33diff = Dict.diff
18
34
35+toList : Set t -> [t]
19toList = Dict.keys
36toList = Dict.keys
37+
38+fromList : [t] -> Set t
20fromList = List.foldl (\k t -> Dict.insert k () t) empty
39fromList = List.foldl (\k t -> Dict.insert k () t) empty
21
40
41+foldl : (a -> b -> b) -> b -> Set a -> b
22−foldl f = Dict.foldl (\k v b -> f k b)
42+foldl f = Dict.foldl (\k _ b -> f k b)
43+
44+foldr : (a -> b -> b) -> b -> Set a -> b
23−foldr f = Dict.foldr (\k v b -> f k b)
45+foldr f = Dict.foldr (\k _ b -> f k b)
46+
47+map : (a -> b) -> Set a -> Set b
24−map f t = fromList . List.map f $ toList t
48+map f = fromList . List.map f . toList