Or a 2 function version if you prefer:

module type Iter =
sig
   type 'a iter
   val current: 'a iter -> 'a
   val next: 'a iter -> 'a iter option
end

Iterator == lazy list is another way to approach it, and results in a  
slightly different structure.

Sandro


On 26-Feb-09, at 18:56, "Jonathan S. Shapiro" <[email protected]> wrote:

> So I was scratching my head about iterators, and I don't see why
> something like the following would not work.
>
> An iterator is a structure or capsule having methods value(), next(),
> and hasNext().  value() returns the value at the current "position".
> next() returns an iterator over the "rest" of the collection.
> hasNext() tests for termination.
>
> Given a construct like this, "forall" is simply a procedure that
> applies a function to all values:
>
>   forall: (fn (by-ref (Iterator 'a)) (fn 'a -> ()) -> ())
>
> I'ld have to scratch my head a second about "fold", but I'm sure it's
> comparably straightforward. The main issue here is to ensure that
> appropriate inlining happens so that the higher-order nature of the
> construct gets compiled out appropriately.
>
> shap
> _______________________________________________
> bitc-dev mailing list
> [email protected]
> http://www.coyotos.org/mailman/listinfo/bitc-dev
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to