-
Notifications
You must be signed in to change notification settings - Fork 24
/
State.hs
32 lines (24 loc) · 898 Bytes
/
State.hs
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
{-@ LIQUID "--reflection" @-}
{-@ LIQUID "--ple" @-}
module State where
import Prelude hiding ((++), const, max)
import ProofCombinators
data GState k v = Init v | Bind k v (GState k v)
{-@ reflect init @-}
init :: v -> GState k v
init v = Init v
{-@ reflect set @-}
set :: GState k v -> k -> v -> GState k v
set s k v = Bind k v s
{-@ reflect get @-}
get :: (Eq k) => GState k v -> k -> v
get (Init v) _ = v
get (Bind k v s) key = if key == k then v else get s key
{-@ lemma_get_set :: k:_ -> v:_ -> s:_ -> { get (set s k v) k == v } @-}
lemma_get_set :: k -> v -> GState k v -> Proof
lemma_get_set _ _ _ = ()
{-@ lemma_get_not_set :: k0:_ -> k:{k /= k0} -> val:_ -> s:_
-> { get (set s k val) k0 = get s k0 } @-}
lemma_get_not_set :: k -> k -> v -> GState k v -> Proof
lemma_get_not_set _ _ _ (Bind {}) = ()
lemma_get_not_set _ _ _ (Init {}) = ()