Skip to content

Instantly share code, notes, and snippets.

@atacratic
Created January 29, 2020 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atacratic/65091f5b9ddb2a337b21b7c11c1e971f to your computer and use it in GitHub Desktop.
Save atacratic/65091f5b9ddb2a337b21b7c11c1e971f to your computer and use it in GitHub Desktop.
example multihandler in Unison
-- An example multihandler.
-- Pipe messages out of the first argument computation into the second.
pipe : Request (Send m) () -> Request (Receive m) a ->{Abort} a
pipe sender receiver =
case receiver of
{ Receive.receive -> kr } ->
case sender of
{ Send.send m -> ks } -> pipe (step ks) (step '(kr m))
{ _ } -> Abort.abort
{ a } -> a
-- Utility function to get the first ability request emitted by a computation.
step : '{e} a -> Request e a
step k =
h : Request e a -> Request e a
h r = r
handle !k with h
pipe' : ('{Send m} ()) -> ('{Receive m} a) ->{Abort} a
pipe' sender receiver =
handle !receiver with (pipe (step sender))
ability Send a where
send : a -> ()
ability Receive a where
receive : a
ability Abort where
abort : a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment