unison/unison-src/tests/state4a.u
2021-08-24 11:33:27 -07:00

27 lines
535 B
Plaintext

structural ability State s where
put : s -> {State s} ()
get : {State s} s
state : s -> Request (State s) a -> s
state s = cases
{ State.get -> k } -> handle k s with state s
{ State.put snew -> k } -> handle k () with state snew
{ a } -> s
modify : (s ->{} s) -> {State s} ()
modify f = State.put (f State.get)
increment : '{State Nat} ()
increment = '(modify ((+) 1))
ex : Nat
ex = handle
State.put (11 + 1)
-- !increment
-- !increment
-- !increment
State.get -- should be 15, amirite??
with state 10
> ex