From d957daab1f20c62f969904c534c0eb1277165378 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Sun, 12 Dec 2010 23:26:53 -0500 Subject: [PATCH] update tree_monadize.ml Signed-off-by: Jim Pryor --- code/tree_monadize.ml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/code/tree_monadize.ml b/code/tree_monadize.ml index d9c5a590..70e7df98 100644 --- a/code/tree_monadize.ml +++ b/code/tree_monadize.ml @@ -232,20 +232,30 @@ TreeReader.monadize asker t1 env;; +(* 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;; @@ -261,11 +271,8 @@ TreeCont.monadize (fun a k -> a :: k a) t1 initial_continuation;; 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;; + -- 2.11.0