-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathclone_is_tricky.ml
35 lines (33 loc) · 978 Bytes
/
clone_is_tricky.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(* Multi-shot continuations don't play nicely with linear resources.
* This program illustrates that resuming an inner one-shot continuation
* within an outer multi-shot context causes a runtime error.
*)
open Effect
open Effect.Deep
type _ Effect.t += Foo : unit Effect.t
type _ Effect.t += Bar : unit Effect.t
let _ =
let run () =
try_with perform Foo
{
effc =
(fun (type a) (e : a Effect.t) ->
match e with
| Foo ->
Some (fun (k : (a, _) continuation) -> continue k (perform Bar))
(* This continuation is resumed twice *)
| _ -> None);
}
in
try_with run ()
{
effc =
(fun (type a) (e : a Effect.t) ->
match e with
| Bar ->
Some
(fun (k : (a, _) continuation) ->
continue (Multicont.Deep.clone_continuation k) ();
continue k ())
| _ -> None);
}