Dear KC, On 09/03/2017 12:53, KC Sivaramakrishnan wrote: > Thanks for the wonderful library and the excellent documentation. I have > a feature request. Could you provide a python-style generator for > traversing the data structure on demand? For a binary tree: > > type 'a t = Leaf | Node of 'a t * 'a * 'a t > > I envision a `mk_gen` function: > > val mk_gen : 'a t -> (unit -> 'a option) > (** [mk_gen t] returns a generator function [f], which when invoked > performs 1-step of the traversal and returns [Some v], where [v] > is the node value. [f] returns [None] when the traversal is done. *) Thanks for this excellent question, which I had not thought about. A quick answer might be that, if you are using OCaml + effect handlers, it should be fairly easy for you to perform control inversion and turn a producer-controlled traversal (as performed by an [iter] visitor) into a consumer-controlled traversal. That said, I was able to come up with a solution in pure OCaml. It is somewhat unexpected and (I think) quite nice, so I am posting it (with comments) on the list (see attached file). If there is demand, most of this code could be made part of the VisitorsRuntime library. Best regards, -- François Pottier francois.pottier@inria.fr http://gallium.inria.fr/~fpottier/