unfold
Stephen Weeks
MLton@sourcelight.com
Mon, 30 Jul 2001 17:57:03 -0700
> I'd vote for the following:
>
> val fold: 'a t * 'b * ('a * 'b -> 'b) -> 'b
> val foldi: 'a t * 'b * (int * 'a * 'b -> 'b) -> 'b
>
> val unfold: 'b * ('b -> ('a * 'b) option) -> 'a t
> val unfoldi: int * 'b * (int * 'b -> ('a * 'b)) -> 'a t
>
> (Note: this changes the type of the old unfold. Why didn't the unfolding
> function get the index?
It did, that's what unfoldi was for (analogous with foldi).
Anyways, I like your compromise. There's still unfoldr and unfoldri, but that's
it.
> How could you have unfoldi and unfoldi'? Particularly for vector/arrays?
I was only thinking of lists.
> What am I supposed to do if my generator returns NONE before I've filled
> up the vector/array?
I never mix the option ones with ones that specify the size.