File: reperform.ml

package info (click to toggle)
js-of-ocaml 5.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,020 kB
  • sloc: ml: 91,250; javascript: 57,289; ansic: 315; makefile: 271; lisp: 23; sh: 6; perl: 4
file content (37 lines) | stat: -rw-r--r-- 978 bytes parent folder | download
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
36
37
(* TEST
 *)

open Effect
open Effect.Deep

type _ t += E : int -> int t
          | F : unit t

let rec nest = function
  | 0 -> perform (E 42)
  | n ->
     match_with (fun _ -> Printf.printf "[%d\n" n; nest (n - 1)) ()
     { retc = (fun x -> Printf.printf " %d]\n" n; x);
       exnc = (fun e -> Printf.printf " !%d]\n" n; raise e);
       effc = fun (type a) (e : a t) ->
         match e with
         | F -> Some (fun k -> assert false)
         | _ -> None }

let () =
  match_with nest 5
  { retc = (fun x -> Printf.printf "= %d\n" x);
    exnc = (fun e -> raise e);
    effc = fun (type a) (e : a t) ->
      match e with
      | E n -> Some (fun (k : (a, _) continuation) -> continue k (n + 100))
      | _ -> None }

let () =
  match_with nest 5
  { retc = (fun x -> assert false);
    exnc = (fun e -> Printf.printf "%s\n" (Printexc.to_string e));
    effc = fun (type a) (e : a t) ->
      match e with
      | F -> Some (fun k -> assert false)
      | _ -> None }