Skip to content

Instantly share code, notes, and snippets.

@pchiusano
Created May 8, 2019 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pchiusano/e20bf962bd00936d10d7f6aa4f0f1adf to your computer and use it in GitHub Desktop.
Save pchiusano/e20bf962bd00936d10d7f6aa4f0f1adf to your computer and use it in GitHub Desktop.
Abilities in Unison
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