-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeap.hs
More file actions
30 lines (23 loc) · 903 Bytes
/
Heap.hs
File metadata and controls
30 lines (23 loc) · 903 Bytes
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
module Heap.Heap where
{-@ class measure hsize :: forall a. a -> Int @-}
{-@ class Heap h where
empty :: forall a. Ord a =>
{h:h a | 0 == hsize h}
isEmpty :: forall a. Ord a =>
h:h a -> {v:Bool | v <=> (0 == hsize h)}
insert :: forall a. Ord a =>
a -> h0:h a -> {h1:h a | (hsize h1) == (hsize h0) + 1}
merge :: forall a. Ord a =>
h0:h a -> h1:h a -> {h2:h a | (hsize h2) == (hsize h0) + (hsize h1)}
findMin :: forall a. Ord a =>
{h:h a | hsize h /= 0} -> a
deleteMin :: forall a. Ord a =>
{h0:h a | hsize h0 /= 0} -> {h1: h a | (hsize h1) == (hsize h0) - 1}
@-}
class Heap h where
empty :: Ord a => h a
isEmpty :: Ord a => h a -> Bool
insert :: Ord a => a -> h a -> h a
merge :: Ord a => h a -> h a -> h a
findMin :: Ord a => h a -> a
deleteMin :: Ord a => h a -> h a