1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
module Data.Set
( Set, null, size, fromList, empty, insert, member, delete
, deleteAll, union, toList, difference
) where
import qualified Data.Map as Map
type Set key = Map.Map key ()
empty :: Set key
empty = Map.empty
fromList :: Ord key => [key] -> Set key
fromList xs = Map.fromList [ (x, ()) | x <- xs]
null :: Set key -> Bool
null = Map.null
insert :: Ord key => key -> Set key -> Set key
insert k s = Map.insert k () s
delete :: Ord key => key -> Set key -> Set key
delete k s = Map.delete k s
deleteAll :: Ord key => [key] -> Set key -> Set key
deleteAll ks s = Map.deleteAll ks s
size :: Set key -> Int
size = Map.size
member :: Ord key => key -> Set key -> Bool
member = Map.member
difference :: Ord key => Set key -> Set key -> Set key
difference = Map.difference
toList :: Set key -> [key]
toList = Map.keys
union :: Ord key => Set key -> Set key -> Set key
union = Map.union
|