Generators in Haskell
We translate the in-order tree traversal example from an old article Generators in Icon, Python, and Scheme, 2004.
using Haskell and delimited continuations rather than call/cc + mutation. The code is shorter, and it even types. To be honest, we actually translate the OCaml code generator.ml
In this code, we use a single global prompt (that is, ordinary shift0) Generator2.hs shows the need for several prompts.
yield is a keyword. In Haskell, it is a regular function.
Furthermore, it is a user-defined function, in one line of code.
To get generators there is no need to extend a language.
The enumerator: the for-loop essentially
The in_order function itself: compare with the Python version