Created
May 8, 2019 13:54
-
-
Save pchiusano/e20bf962bd00936d10d7f6aa4f0f1adf to your computer and use it in GitHub Desktop.
Abilities in Unison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ability State s where | |
put : s ->{State s} () | |
get : {State s} s | |
state : s -> Effect (State s) a -> 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 } -> a | |
modify : (s ->{} s) ->{State s} () | |
modify f = State.put (f State.get) | |
ex : (Text, Nat) | |
ex = handle (state 10) in -- starting state: 10 | |
modify (x -> x + 1) -- 11 | |
("hello", State.get + State.get) -- 11 + 11 = 22 | |
> ex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment