edits
[lambda.git] / using_continuations_to_solve_same_fringe.mdwn
index b65add6..1c980a4 100644 (file)
@@ -58,15 +58,15 @@ the thunk by applying it to the unit:
 
 <pre>
 # let rec make_int_stream i = Next (i, fun () -> make_int_stream (i + 1));;
 
 <pre>
 # let rec make_int_stream i = Next (i, fun () -> make_int_stream (i + 1));;
-val make_int_stream : int -> int stream = <fun>
+val make_int_stream : int -> int stream = [fun]
 # let int_stream = make_int_stream 1;;
 # let int_stream = make_int_stream 1;;
-val int_stream : int stream = Next (1, <fun>)         (* First element: 1 *)
+val int_stream : int stream = Next (1, [fun])         (* First element: 1 *)
 # match int_stream with Next (i, rest) -> rest;;      
 # match int_stream with Next (i, rest) -> rest;;      
-- : unit -> int stream = <fun>                        (* Rest: a thunk *)
+- : unit -> int stream = [fun]                        (* Rest: a thunk *)
 
 (* Force the thunk to compute the second element *)
 # (match int_stream with Next (i, rest) -> rest) ();;
 
 (* Force the thunk to compute the second element *)
 # (match int_stream with Next (i, rest) -> rest) ();;
-- : int stream = Next (2, <fun>)      
+- : int stream = Next (2, [fun])      
 </pre>
 
 You can think of `int_stream` as a functional object that provides
 </pre>
 
 You can think of `int_stream` as a functional object that provides
@@ -115,11 +115,14 @@ Notice the forcing of the thunks in the recursive call to
 - : bool = false
 </pre>
 
 - : bool = false
 </pre>
 
-Now, this implementation is a bit silly, since in order to convert the
-trees to leaf streams, our tree_monadizer function has to visit every
-node in the tree.  But if we needed to compare each tree to a large
-set of other trees, we could arrange to monadize each tree only once,
-and then run compare_streams on the monadized trees.
+Now, you might think that this implementation is a bit silly, since in
+order to convert the trees to leaf streams, our tree_monadizer
+function has to visit every node in the tree, so we'd have to traverse
+the entire tree at some point.  But you'd be wrong: part of what gets
+suspended in the thunking of the stream is the computation of the rest
+of the monadized tree.  Proving this claim requires adding print
+statements (or other tracing technology) within the tree monadizer
+function.
 
 By the way, what if you have reason to believe that the fringes of
 your trees are more likely to differ near the right edge than the left
 
 By the way, what if you have reason to believe that the fringes of
 your trees are more likely to differ near the right edge than the left