mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-05 14:17:33 +03:00
40 lines
767 B
Plaintext
40 lines
767 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 Nat} ()
|
|
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 : Nat
|
|
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
|
|
|