unison/unison-src/tests/state2b.u
2018-09-05 14:49:14 -04:00

40 lines
771 B
Plaintext

--State2 effect
type Optional a = None | Some a
effect State s where
put : s -> {State s} ()
get : {State s} s
state : s -> Effect (State s) a -> (s, a)
state s eff = case eff of
{ State.get -> k } -> handle (state s) in k s
{ State.put snew -> k } -> handle (state snew) in k ()
{ a } -> (s, a)
modify : (s -> s) -> {State s} ()
modify f = State.put (f State.get)
increment : '{State UInt64} ()
increment = '(modify ((+) 1))
second : (a, b) -> b
second p = case p of (_,b) -> b
first : (a, b) -> a
first p = case p of (a,_) -> a
ex : UInt64
ex =
result = handle (state 10) in
State.put (11 + 1)
State.put (5 + 15)
()
first result
-- should return `20`, but actually returns `12`
-- seems like only one `put` is actually being run
ex