[MLton-user] Iterator

andrew cooke andrew@acooke.org
Thu, 4 Mar 2004 23:01:31 -0300 (CLST)


Hi,

I'd like to program an iterator/coroutine/lazy list - I have a data
structure and want to provide a list-like interface to the contents, but
the list elements should only be generated on demand.

What's the most *efficient* way to do this in MLTon?  I couldn't find
direct support for lazy evaluation.  The continuation docs mention time
proportional to stack size, which looks nasty.  Should I use threads?  Or
am I making life too complicated and should I code something directly
using a mutable reference (I'm used to programming in Haskell, so that
last thought only just occurred to me, but I'm guessing it's the way to
go)?

Thanks for what feels like a nice, solid compiler.  Great error messages.

Andrew

(PS Playing around trying to make a program to play "go").

-- 
  __ _ __ ___  ___| |_____   work web site: http://www.ctio.noao.edu/~andrew
 / _` / _/ _ \/ _ \ / / -_)  personal web site: http://www.acooke.org/andrew
 \__,_\__\___/\___/_\_\___|  personal gallery: http://www.acooke.org/pancito