<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffee" text="#000000">
Vesa Karvonen wrote:<br>
<blockquote
cite="mid:9e43b9a0704170036l6da22fccl8e8d7a2aba750118@mail.gmail.com"
type="cite">I don't like the type of this. A thunk is a delayed
computation that you
<br>
invoke for the computed value (unit thunk is a sign of a mistake). The
<br>
type of iterate seems error prone to me. For example, you can easily
call
<br>
it accidentally with a partially applied function inside an explicit
<br>
thunk:
<br>
<br>
iterate (fn () => curried a b (* Oops! Forgot the last argument: c.
*)) n
<br>
<br>
I think that when a non-unit return value is always ignored, it should
be
<br>
explicitly visible at the call site. For the same reason, I don't
<br>
particularly like the type of app and even less the type of appWith in
the
<br>
MONAD_EX signature, but those are more arguable, because it may be
costly
<br>
(performance wise) to ignore the result (an extra bind may be
required).
<br>
In this case, however, the cost is always negligible or zero (function
<br>
composition is optimized by all serious ML compilers and in most cases
<br>
with MLton the cost of composing with ignore is literally zero).
<br>
<br>
To me, a more natural function to provide would be either
<br>
<br>
val repeat : Unit.t Effect.t -> Int.t Effect.t
<br>
<br>
or
<br>
<br>
val repeat : 'a Effect.t -> Int.t -> 'a Effect.t
<br>
<br>
(or some permutation of the arguments of either) in the Effect : EFFECT
<br>
structure.
<br>
<br>
</blockquote>
Fair enough, this certainly sounds much better than my proposal
that evolved out of a function I was using in my code.<br>
<br>
<blockquote
cite="mid:9e43b9a0704170036l6da22fccl8e8d7a2aba750118@mail.gmail.com"
type="cite">Instead of writing
<br>
<br>
Thunk.iterate th n
<br>
<br>
you would write (using the former repeat)
<br>
<br>
Effect.repeat (ignore o th) n
<br>
<br>
or (using the latter repeat)
<br>
<br>
Effect.repeat (ignore o th) n ()
<br>
</blockquote>
The latter seems slightly more general, so I'll go with that when I
implement it. Though I suppose there is also the question of whether <br>
<br>
val repeat : 'a Effect.t -> Int.t -> (Int.t -> 'a) Effect.t<br>
<br>
would be even better. This would make the the above example<br>
<br>
Effect.repeat (ignore o th) n |< Fn.const ()<br>
<br>
Alternately, this proposal could be called repeatWith. <br>
<br>
<pre class="moz-signature" cols="72">--
[Geoff Washburn|<a class="moz-txt-link-abbreviated" href="mailto:geoffw@cis.upenn.edu">geoffw@cis.upenn.edu</a>|<a class="moz-txt-link-freetext" href="http://www.cis.upenn.edu/~geoffw/">http://www.cis.upenn.edu/~geoffw/</a>]
</pre>
</body>
</html>