/
delimited.eff
34 lines (26 loc) · 1.01 KB
/
delimited.eff
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
(* This example is described in Section 6.11 of "Programming with Algebraic Effects and
Handlers" by A. Bauer and M. Pretnar. *)
effect Shift : ((int -> int) -> int) -> int
(* Such operations are currently less usefull due to lack of polymorphism in
current version of eff. In version 3.0 it is possible to have a polymorphic
version. *)
let reset =
let rec reset_handler () = handler
| effect (Shift f) k -> with reset_handler () handle (f k)
in
reset_handler ()
;;
(* An example from http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf *)
with reset handle
perform (Shift (fun k -> k (k (k 7)))) * 2 + 1
;;
(* The yin-yang puzzle, see
http://stackoverflow.com/questions/2694679/how-the-yin-yang-puzzle-works
Warning: To run this example you have to turn off type checking:
eff --no-types delimited.eff*)
(*
with reset handle
let yin = (fun k -> perform Print "@"; k) (perform Shift (fun k -> k k)) in
let yang = (fun k -> perform Print "*"; k) (perform Shift (fun k -> k k)) in
yin yang;;
*)