X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Ftree_monadize.ml;fp=code%2Ftree_monadize.ml;h=43ef659f0ad5162eabe0d915a8e90dccdab7ebb6;hp=7c419a342402ce77a965eb1c2810e4b332cdfcde;hb=4528f489f93c2f44f573678dff7359d54d9f9672;hpb=9e8d6010aed681391bd631634115e0aeee968611 diff --git a/code/tree_monadize.ml b/code/tree_monadize.ml index 7c419a34..43ef659f 100644 --- a/code/tree_monadize.ml +++ b/code/tree_monadize.ml @@ -269,3 +269,27 @@ 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;; +(* +(* Tree monad *) + +(* type 'a tree defined above *) +let tree_unit (a: 'a) : 'a tree = Leaf a;; +let rec tree_bind (u : 'a tree) (f : 'a -> 'b tree) : 'b tree = + match u with + | Leaf a -> f a + | Node (l, r) -> Node (tree_bind l f, tree_bind r f);; + +type ('a) treeT_reader = + 'a tree reader;; + +let unit (a: 'a) : 'a tree reader = + reader_unit (Leaf a);; + +let rec bind (u : 'a tree_reader) (f : 'a -> ('b, M) tree) : ('b, M) tree = + match u with + | Leaf a -> M.bind (f a) (fun b -> M.unit (Leaf b)) + | Node (l, r) -> M.bind (bind l f) (fun l' -> + M.bind (bind r f) (fun r' -> + M.unit (Node (l', r'));; + + *)