23 import Types.Data.Bool
28 data Node key value heaps
32 instance Heap hs => Heap (Node k v hs)
34 type Unit k v = Node k v Nil
37 type instance IsEmpty Empty = True
38 type instance IsEmpty (Node k v hs) = False
40 type Insert k v h = Merge (Unit k v) h
42 type family Merge h1 h2
43 type instance Merge h1 Empty = h1
44 type instance Merge Empty h2 = h2
45 type instance Merge (Node k1 v1 hs1) (Node k2 v2 hs2)
47 (Node k1 v1 (Cons (Node k2 v2 hs2) hs1))
48 (Node k2 v2 (Cons (Node k1 v1 hs1) hs2))
50 type family MergeAll hs
51 type instance MergeAll Nil = Empty
52 type instance MergeAll (Cons h Nil) = h
53 type instance MergeAll (Cons h (Cons h' hs))
54 = Merge (Merge h h') (MergeAll hs)
57 type instance FindMin (Node k v hs) = Cons k v
59 type family DeleteMin h
60 type instance DeleteMin Empty = Empty
61 type instance DeleteMin (Node k v hs) = MergeAll hs
63 type family SplitMin h
64 type instance SplitMin (Node k v hs) = Cons k (Cons v (MergeAll hs))