X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;f=manipulating_trees_with_monads.mdwn;h=a05fa2599ed2a9c07878ac4f7df07f790d42573f;hb=c4a2655a636328b4e3fe183717402a02f1d97a90;hp=379ead54ba83234a6546947eb8833f558e188996;hpb=bdb385fa72c726c61102aa4b0ef2914025c371ee;p=lambda.git diff --git a/manipulating_trees_with_monads.mdwn b/manipulating_trees_with_monads.mdwn index 379ead54..a05fa259 100644 --- a/manipulating_trees_with_monads.mdwn +++ b/manipulating_trees_with_monads.mdwn @@ -262,25 +262,25 @@ That is, nothing happens. But we can begin to substitute more interesting functions for the first argument of `treemonadizer`: (* Simulating the tree reader: distributing a operation over the leaves *) - # treemonadizer (fun a c -> c (square a)) t1 (fun i -> i);; + # treemonadizer (fun a k -> k (square a)) t1 (fun i -> i);; - : int tree = Node (Node (Leaf 4, Leaf 9), Node (Leaf 25, Node (Leaf 49, Leaf 121))) (* Simulating the int list tree list *) - # treemonadizer (fun a c -> c [a; square a]) t1 (fun i -> i);; + # treemonadizer (fun a k -> k [a; square a]) t1 (fun i -> i);; - : int list tree = Node (Node (Leaf [2; 4], Leaf [3; 9]), Node (Leaf [5; 25], Node (Leaf [7; 49], Leaf [11; 121]))) (* Counting leaves *) - # treemonadizer (fun a c -> 1 + c a) t1 (fun i -> 0);; + # treemonadizer (fun a k -> 1 + k a) t1 (fun i -> 0);; - : int = 5 We could simulate the tree state example too, but it would require generalizing the type of the continuation monad to - type ('a -> 'b -> 'c) continuation = ('a -> 'b) -> 'c;; + type ('a -> 'b -> 'k) continuation = ('a -> 'b) -> 'k;; The binary tree monad ---------------------