@@ -6,60 +6,61 @@ module Set (empty,singleton,insert,remove
66 ,toList,fromList
77 ) where
88
9+import Maybe (Maybe)
910import Dict as Dict
1011import List as List
1112
12−type Set t = Dict t ()
13+type Set t = Dict.Dict t ()
1314
1415-- Create an empty set.
15−empty : Set (Comparable k)
16+empty : Set comparable
1617empty = Dict.empty
1718
1819-- Create a set with one value.
19−singleton : Comparable k -> Set (Comparable k)
20+singleton : comparable -> Set comparable
2021singleton k = Dict.singleton k ()
2122
2223-- Insert a value into a set.
23−insert : Comparable k -> Set (Comparable k) -> Set (Comparable k)
24+insert : comparable -> Set comparable -> Set comparable
2425insert k = Dict.insert k ()
2526
2627-- Remove a value from a set. If the value is not found, no changes are made.
27−remove : Comparable k -> Set (Comparable k) -> Set (Comparable k)
28+remove : comparable -> Set comparable -> Set comparable
2829remove = Dict.remove
2930
3031-- Determine if a value is in a set.
31−member : Comparable k -> Set (Comparable k) -> Bool
32+member : comparable -> Set comparable -> Bool
3233member = Dict.member
3334
3435-- Get the union of two sets. Keep all values.
35−union : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
36+union : Set comparable -> Set comparable -> Set comparable
3637union = Dict.union
3738
3839-- Get the intersection of two sets. Keeps values that appear in both sets.
39−intersect : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
40+intersect : Set comparable -> Set comparable -> Set comparable
4041intersect = Dict.intersect
4142
4243-- Get the difference between the first set and the second. Keeps values
4344-- that do not appear in the second set.
44−diff : Set (Comparable k) -> Set (Comparable k) -> Set (Comparable k)
45+diff : Set comparable -> Set comparable -> Set comparable
4546diff = Dict.diff
4647
4748-- Convert a set into a list.
48−toList : Set (Comparable k) -> [Comparable k]
49+toList : Set comparable -> [comparable]
4950toList = Dict.keys
5051
5152-- Convert a list into a set, removing any duplicates.
52−fromList : [Comparable k] -> Set (Comparable k)
53+fromList : [comparable] -> Set comparable
5354fromList xs = List.foldl insert empty xs
5455
5556-- Fold over the values in a set, in order from lowest to highest.
56−foldl : (Comparable a -> b -> b) -> b -> Set (Comparable a) -> b
57+foldl : (comparable -> b -> b) -> b -> Set comparable -> b
5758foldl f b s = Dict.foldl (\k _ b -> f k b) b s
5859
5960-- Fold over the values in a set, in order from highest to lowest.
60−foldr : (Comparable a -> b -> b) -> b -> Set (Comparable a) -> b
61+foldr : (comparable -> b -> b) -> b -> Set comparable -> b
6162foldr f b s = Dict.foldr (\k _ b -> f k b) b s
6263
6364-- Map a function onto a set, creating a new set with no duplicates.
64−map : (Comparable a -> Comparable b) -> Set (Comparable a) -> Set (Comparable b)
65+map : (comparable -> comparable') -> Set comparable -> Set comparable'
6566map f s = fromList (List.map f (toList s))