Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Created June 26, 2020 20:15
Show Gist options
  • Save chiroptical/82a79c54e29d828a518f424ad7e09d85 to your computer and use it in GitHub Desktop.
Save chiroptical/82a79c54e29d828a518f424ad7e09d85 to your computer and use it in GitHub Desktop.
Update code from https://github.com/unisonweb/unison/issues/822 to unison version: devel/M1l-171-g8b57038d
ability State s where
Get : s
Put : s -> ()
runState : s -> Request (State s) a -> (s, a)
runState s = cases
{State.Get -> k} ->
handle k s with runState s
{State.Put s -> k} ->
handle !k with runState s
{a} ->
(s, a)
ability Error e where
Throw : e -> a
Catch : (e -> {Error e, t} a) -> '{Error e, t} a -> {Error e} a
runError : Request (Error e) a -> Either e a
runError = cases
{Error.Throw e -> _} -> Left e
{Error.Catch catch try -> k} ->
let z = handle !try with runError
z2 = match z with
Left e -> handle (catch e) with runError
Right a -> Right a
match z2 with
Left e -> Left e
Right a -> handle k a with runError
{x} -> Right x
catchThrownError : '{State Nat, Error ()} Nat
catchThrownError = 'let
Error.Catch
(err -> State.Get)
('let
State.Put 1337
Error.Throw ()
)
State.Get
> handle (handle !catchThrownError with runError) with runState 5
> handle (handle !catchThrownError with runState 5) with runError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment