Created
January 29, 2020 00:39
-
-
Save atacratic/65091f5b9ddb2a337b21b7c11c1e971f to your computer and use it in GitHub Desktop.
example multihandler 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
-- 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