From: Jim Pryor Date: Sun, 5 Dec 2010 15:35:25 +0000 (-0500) Subject: tree_monadize tweaks X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=c9a9cb39ae6852c63c43d80ed4ebb05aec6c1e05 tree_monadize tweaks Signed-off-by: Jim Pryor --- diff --git a/code/tree_monadize.ml b/code/tree_monadize.ml index 08b8d690..7c419a34 100644 --- a/code/tree_monadize.ml +++ b/code/tree_monadize.ml @@ -196,6 +196,36 @@ let int_readerize : int -> int Reader_monad.monad = 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;; @@ -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;; -