Skip to content

Instantly share code, notes, and snippets.

Created Jan 29, 2020
What would you like to do?
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