[MLton-user] Extended Basis Library: iterating thunks

Vesa Karvonen vesa.a.j.k at gmail.com
Wed Apr 18 00:06:56 PDT 2007


On 4/17/07, Geoffrey Alan Washburn <geoffw at cis.upenn.edu> wrote:
[...]
>      The latter seems slightly more general, so I'll go with that when I
> implement it.

Ok.  Alternatively, one could introduce a function, say

  val seal : 'a Effect.t -> 'a -> Unit.t Effect.t

So, one could write

  Effect.repeat (Effect.seal ef a) n

This would make it more convenient to repeat unit effects at the
cost of making it slightly less convenient to repeat non-unit effects.

I don't know which leads to less client code. It depends on the
distribution of unit vs non-unit effects.

Actually, I think I'll add Effect.seal anyway. It could be handy.

> Though I suppose there is also the question of whether
>
>      val repeat : 'a Effect.t -> Int.t -> (Int.t -> 'a) Effect.t
>
>  would be even better.  This would make the the above example
>
>       Effect.repeat (ignore o th) n |< Fn.const ()
>
>  Alternately, this proposal could be called repeatWith.

The repeatWith name makes me think of the alternatives

  val repeat : Unit.t Effect.t -> Int.t Effect.t
  val repeatWith : 'a Effect.t -> 'a -> Int.t Effect.t

where repeatWith ef = repeat o seal ef.

OTOH, the type of repeatWith makes me think of tabulate.
Hmm... A simpler alternative could be Effect.tabulate

  val tabulate : Int.t -> Int.t Effect.t

So, given

  ef : 'a Effect.t
  i2a : Int.t -> 'a

for some 'a, one could say

  tabulate n (ef o i2a)

instead of

  repeatWith ef n i2a

Also note the existing function Basic.repeat:

   val repeat : 'a UnOp.t -> Int.t -> 'a UnOp.t

-Vesa Karvonen



More information about the MLton-user mailing list