mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-26 11:07:48 +03:00
27 lines
526 B
Plaintext
27 lines
526 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
|