tree_monadize tweaks
[lambda.git] / code / tree_monadize.ml
index c751b36..7c419a3 100644 (file)
@@ -184,7 +184,7 @@ module TreeCont =  Tree_monadizer2(Continuation_monad);;
  *)
 
 
-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
@@ -196,13 +196,43 @@ let int_readerize : int -> int reader =
 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
@@ -221,7 +251,7 @@ TreeList.monadize (fun i -> [ [i;i*i] ]) t1;;
 
 (* 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
@@ -239,4 +269,3 @@ TreeCont.monadize (fun a k -> k [a; a*a]) t1 initial_continuation;;
 let initial_continuation = fun t -> 0 in
 TreeCont.monadize (fun a k -> 1 + k a) t1 initial_continuation;;
 
-