(********************************************************************)
(*  OCaml code from the book ``Learn Programming with OCaml''       *)
(*  See https://usr.lmf.cnrs.fr/lpo/                                *)
(*                                                                  *)
(*  Sylvain Conchon and Jean-Christophe Filliâtre                   *)
(*  Copyright 2025 Université Paris-Saclay and CNRS                 *)
(*                                                                  *)
(*  Openly licensed via CC BY SA 4.0                                *)
(*  See https://creativecommons.org/licenses/by-sa/4.0/deed.en      *)
(********************************************************************)

(* Program 78 on page 337
   Cursors on trees (infix traversal) *)

  type 'a enum = Top | Left of 'a * 'a tree * 'a enum

  let rec leftmost t e = match t with
    | E -> e
    | N (l, x, r) -> leftmost l (Left (x, r, e))

  let start t =
    leftmost t Top

  let step = function
    | Top -> raise Exit
    | Left (x, r, e) -> x, leftmost r e

This document was generated using caml2html