-LR.(run (distribute (fun i -> R.(asks (fun e -> e i))) l2 >>= fun j -> LR.(plus (unit j) (unit (succ j))))) (fun i -> i*10);;
-(* int list = [10; 11; 20; 21; 30; 31; 40; 41; 50; 51] *)
-
-TR.(run_exn (distribute (fun i -> R.(asks (fun e -> e i))) t2 >>= fun j -> TR.(plus (unit j) (unit (succ j))))) (fun i -> i*10);;
-(*
-int T.tree option =
-Some
- (T.Node
- (T.Node (T.Leaf 10, T.Leaf 11),
- T.Node
- (T.Node
- (T.Node (T.Node (T.Leaf 20, T.Leaf 21), T.Node (T.Leaf 30, T.Leaf 31)),
- T.Node (T.Leaf 40, T.Leaf 41)),
- T.Node (T.Leaf 50, T.Leaf 51))))
- *)
-
-LS.run (LS.distribute (fun i -> if i = -1 then S.get else if i < 0 then S.(puts succ >> unit 0) else S.unit i) [10;-1;-2;-1;20]) 0;;
-(*
-- : S.store list * S.store = ([10; 0; 0; 1; 20], 1)
-*)
-
-*)
-
-let id : 'z. 'z -> 'z = fun x -> x
-
-let example n : (int * int) =
- Continuation_monad.(let u = callcc (fun k ->
- (if n < 0 then k 0 else unit [n + 100])
- (* all of the following is skipped by k 0; the end type int is k's input type *)
- >>= fun [x] -> unit (x + 1)
- )
- (* k 0 starts again here, outside the callcc (...); the end type int * int is k's output type *)
- >>= fun x -> unit (x, 0)
- in run0 u)
-
-
-(* (+ 1000 (prompt (+ 100 (shift k (+ 10 1))))) ~~> 1011 *)
-let example1 () : int =
- Continuation_monad.(let v = reset (
- let u = shift (fun k -> unit (10 + 1))
- in u >>= fun x -> unit (100 + x)
- ) in let w = v >>= fun x -> unit (1000 + x)
- in run0 w)
-
-(* (+ 1000 (prompt (+ 100 (shift k (k (+ 10 1)))))) ~~> 1111 *)
-let example2 () =
- Continuation_monad.(let v = reset (
- let u = shift (fun k -> k (10 :: [1]))
- in u >>= fun x -> unit (100 :: x)
- ) in let w = v >>= fun x -> unit (1000 :: x)
- in run0 w)
-
-(* (+ 1000 (prompt (+ 100 (shift k (+ 10 (k 1)))))) ~~> 1111 but added differently *)
-let example3 () =
- Continuation_monad.(let v = reset (
- let u = shift (fun k -> k [1] >>= fun x -> unit (10 :: x))
- in u >>= fun x -> unit (100 :: x)
- ) in let w = v >>= fun x -> unit (1000 :: x)
- in run0 w)
-
-(* (+ 100 ((prompt (+ 10 (shift k k))) 1)) ~~> 111 *)
-(* not sure if this example can be typed without a sum-type *)
-
-(* (+ 100 (prompt (+ 10 (shift k (k (k 1)))))) ~~> 121 *)
-let example5 () : int =
- Continuation_monad.(let v = reset (
- let u = shift (fun k -> k 1 >>= fun x -> k x)
- in u >>= fun x -> unit (10 + x)
- ) in let w = v >>= fun x -> unit (100 + x)
- in run0 w)
-
-
-;;
-
-(1011, 1111, 1111, 121);;
-(example1(), example2(), example3(), example5());;
-((111,0), (0,0));;
-(example ~+10, example ~-10);;
-
-module C = Continuation_monad
-module TC = T.T(C)
-
-let testc df ic =
- C.runk TC.(run_exn (distribute df t1)) ic;;
-
-
-(*
-(* do nothing *)
-let initial_continuation = fun t -> t in
-TreeCont.monadize t1 Continuation_monad.unit initial_continuation;;
-*)
-testc (C.unit) id;;
-
-(*
-(* count leaves, using continuation *)
-let initial_continuation = fun t -> 0 in
-TreeCont.monadize t1 (fun a k -> 1 + k a) initial_continuation;;
-*)
-
-testc C.(fun a -> shift (fun k -> k a >>= fun v -> unit (1 + v))) (fun t -> 0);;
-
-(*
-(* convert tree to list of leaves *)
-let initial_continuation = fun t -> [] in
-TreeCont.monadize t1 (fun a k -> a :: k a) initial_continuation;;
-*)
-
-testc C.(fun a -> shift (fun k -> k a >>= fun v -> unit (a::v))) (fun t -> ([] : int list));;
-
-(*
-(* square each leaf using continuation *)
-let initial_continuation = fun t -> t in
-TreeCont.monadize t1 (fun a k -> k (a*a)) initial_continuation;;
-*)
-
-testc C.(fun a -> shift (fun k -> k (a*a))) (fun t -> t);;
-
-
-(*
-(* replace leaves with list, using continuation *)
-let initial_continuation = fun t -> t in
-TreeCont.monadize t1 (fun a k -> k [a; a*a]) initial_continuation;;
-*)