X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Ftree_monadize.ml;h=7c419a342402ce77a965eb1c2810e4b332cdfcde;hp=08b8d690302825d6c2f60b6b3a656c18d9db0677;hb=c9a9cb39ae6852c63c43d80ed4ebb05aec6c1e05;hpb=323b2661061ae22ca28b4bf79564e1d1bc9bc446 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;; -