*)
-let int_readerize : int -> int reader =
+let int_readerize : int -> int Reader_monad.monad =
fun (a : int) -> fun (env : int -> int) -> env a;;
(* int_readerize takes an int and returns a Reader monad that
let env = fun i -> i + i in
TreeReader.monadize int_readerize t1 env;;
+(* You can also avoid declaring a separate toplevel TreeReader module
+ * (or even a separate Reader_monad module) by ysing one of these forms:
+ * ...
+ * let module T = Tree_monadizer(Reader_monad) in
+ * T.monadize int_readerize t1 env;;
+ * or:
+ * ...
+ * let env = fun i -> i + i in
+ * let module Monad = struct
+ * type env = int -> int;;
+ * type 'a monad = env -> 'a;;
+ * let unit a : 'a monad = fun e -> a;;
+ * let bind (u : 'a monad) (f : 'a -> 'b monad) : 'b monad =
+ * fun e -> f (u e) e;;
+ * end in
+ * let module T = Tree_monadizer(Monad) in
+ * T.monadize int_readerize t1 env;;
+ * or:
+ * ...
+ * let module T = Tree_monadizer(struct
+ * type env = int -> int;;
+ * type 'a monad = env -> 'a;;
+ * let unit a : 'a monad = fun e -> a;;
+ * let bind (u : 'a monad) (f : 'a -> 'b monad) : 'b monad =
+ * fun e -> f (u e) e;;
+ * end) in
+ * T.monadize int_readerize t1 env;;
+ *)
+
+
(* square each leaf *)
let env = fun i -> i * i in
TreeReader.monadize int_readerize t1 env;;
-let incrementer : int -> int state =
+let incrementer : int -> int State_monad.monad =
fun (a : int) -> fun s -> (a, s+1);;
(* incrementer takes an 'a and returns it wrapped in a
(* do nothing *)
let initial_continuation = fun t -> t in
-TreeCont.monadize cont_unit t1 initial_continuation;;
+TreeCont.monadize Continuation_monad.unit t1 initial_continuation;;
(* convert tree to list of leaves *)
let initial_continuation = fun t -> [] in
let initial_continuation = fun t -> 0 in
TreeCont.monadize (fun a k -> 1 + k a) t1 initial_continuation;;
-