+(* count leaves *)
+
let incrementer : int -> int State_monad.m =
fun (a : int) -> fun s -> (a, s+1);;
-
(* incrementer takes an 'a and returns it wrapped in a
* State monad that increments the store *)
-(* count leaves *)
let initial_store = 0 in
TreeState.monadize incrementer t1 initial_store;;
+(* annotate leaves as they're visited *)
+
+let annotater : int -> (int * int) State_monad.m =
+ fun (a : int) -> fun s -> ((a,s+1), s+1);;
+
+let initial_store = 0 in
+TreeState.monadize annotater t1 initial_store;;
+
+
+(* copy tree with different choices for leaves *)
+let chooser i = if i = 2 then [20; 21] else [i];;
-(* replace leaves with list *)
-TreeList.monadize (fun i -> [ [i;i*i] ]) t1;;
+TreeList.monadize chooser t1;;
let initial_continuation = fun t -> t in
TreeCont.monadize (fun a k -> k (a*a)) t1 initial_continuation;;
-(* replace leaves with list, using continuation *)
-let initial_continuation = fun t -> t in
-TreeCont.monadize (fun a k -> k [a; a*a]) t1 initial_continuation;;
-
(* count leaves, using continuation *)
let initial_continuation = fun t -> 0 in
TreeCont.monadize (fun a k -> 1 + k a) t1 initial_continuation;;
+