Using continuations to solve the same-fringe problem ---------------------------------------------------- The problem ----------- The problem, recall, is to take two trees and decide whether they have the same leaves in the same order.
``` ta            tb          tc
.             .           .
_|__          _|__        _|__
|  |          |  |        |  |
1  .          .  3        1  .
_|__       _|__           _|__
|  |       |  |           |  |
2  3       1  2           3  2

let ta = Node (Leaf 1, Node (Leaf 2, Leaf 3));;
let tb = Node (Node (Leaf 1, Leaf 2), Leaf 3);;
let tc = Node (Leaf 1, Node (Leaf 3, Leaf 2));;
```
```# let rec make_int_stream i = Next (i, fun () -> make_int_stream (i + 1));;
val make_int_stream : int -> int stream = [fun]

# let int_stream = make_int_stream 1;;
val int_stream : int stream = Next (1, [fun])         (* First element: 1 *)

# let tail = match int_stream with Next (i, rest) -> rest;;
val tail : unit -> int stream =                  (* Tail: a thunk *)

(* Force the thunk to compute the second element *)
# tail ();;
- : int stream = Next (2, [fun])                     (* Second element: 2 *)

# match tail () with Next (_, rest) -> rest ();;
- : int stream = Next (3, )                     (* Third element: 3 *)
```
You can think of `int_stream` as a functional object that provides access to an infinite sequence of integers, one at a time. It's as if we had written `[1;2;...]` where `...` meant "continue for as long as some other process needs new integers".