-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from robur-coop/handle-other-effects
Be able to perform unhandled effects
- Loading branch information
Showing
7 changed files
with
148 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ | |
Fatal error: exception Miou.Still_has_children | ||
[2] | ||
$ ./t25.exe | ||
$ ./t28.exe |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
type _ Effect.t += Foo : unit Effect.t | ||
|
||
let prgm () = | ||
let prm = Miou.call @@ fun () -> Effect.perform Foo in | ||
Miou.await_exn prm | ||
|
||
let handler_foo fn v = | ||
let open Effect.Deep in | ||
let retc = Fun.id in | ||
let exnc = raise in | ||
let effc : type c. c Effect.t -> ((c, 'a) continuation -> 'b) option = | ||
function | ||
| Foo -> Some (fun k -> continue k ()) | ||
| _ -> None | ||
in | ||
match_with fn v { retc; exnc; effc } | ||
|
||
let () = | ||
Miou.run ~handler:{ Miou.handler= handler_foo } @@ fun () -> | ||
let prm = Miou.call @@ fun () -> Effect.perform Foo in | ||
Miou.await_exn prm | ||
|
||
let () = | ||
Miou.run ~handler:{ Miou.handler= handler_foo } @@ fun () -> | ||
let prm = Miou.call_cc @@ fun () -> Effect.perform Foo in | ||
Miou.await_exn prm | ||
|
||
type _ Effect.t += Bar : unit Effect.t | ||
|
||
let handler_bar fn v = | ||
let open Effect.Deep in | ||
let retc = Fun.id in | ||
let exnc = raise in | ||
let effc : type c. c Effect.t -> ((c, 'a) continuation -> 'b) option = | ||
function | ||
| Bar -> Some (fun k -> continue k ()) | ||
| _ -> None | ||
in | ||
match_with fn v { retc; exnc; effc } | ||
|
||
let ( <.> ) { Miou.handler= foo } { Miou.handler= bar } = | ||
{ Miou.handler= (fun fn v -> (foo (bar fn)) v) } | ||
|
||
let () = | ||
let foo = { Miou.handler= handler_foo } in | ||
let bar = { Miou.handler= handler_bar } in | ||
Miou.run ~handler:(foo <.> bar) @@ fun () -> | ||
let prm0 = Miou.call @@ fun () -> Effect.perform Foo in | ||
let prm1 = Miou.call @@ fun () -> Effect.perform Bar in | ||
Miou.await_exn prm0; Miou.await_exn prm1 |