open SMLofNJ.Cont (* open module that provides continuations *) datatype tree = leaf of int | node of tree*tree datatype coA = A of (int* coB) cont (* searchA wants an int and a B-continuation *) and coB = B of coA cont (* searchB wants an A-continuation *) fun resumeA(x, A k) = callcc(fn k' => throw k (x, B k')) fun resumeB( B k) = callcc(fn k' => throw k (A k')) exception DISAGREE exception DONE fun searchA(leaf(x),(y, other: coB)) = if x=y then resumeB(other) else raise DISAGREE | searchA(node(t1,t2), other) = searchA(t2, searchA(t1, other)) fun searchB(leaf(x), other : coA) = resumeA(x,other) | searchB(node(t1,t2), other) = searchB(t2, searchB(t1, other)) fun startB(t: tree) = callcc(fn k => (searchB(t, A k); raise DONE)) fun compare(t1,t2) = searchA(t1, startB(t2))