[bitc-dev] Iterators
Sandro Magi
smagi at higherlogics.com
Thu Feb 26 19:29:16 EST 2009
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" <shap at eros-os.com> 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
> bitc-dev at coyotos.org
> http://www.coyotos.org/mailman/listinfo/bitc-dev
More information about the bitc-dev
mailing list