FW: Haskell accumulator

Jeffrey Palmer jeffrey.palmer@acm.org
Thu, 13 Jun 2002 18:41:49 -0500


On Thursday 13 June 2002 05:29 pm, Dominic Cooney wrote:
> Paul Graham is collecting canonical accumulator generators at
> http://www.paulgraham.com/accgen.html , and has Dylan, E, JavaScript,
> various dialects Lisp, Lua, Rebol, Ruby, Perl, Python and Smalltalk.
>
> Could the serious Haskellers comment on this attempt of mine?
>
> foo n =3D do
>   n' <- newIORef n
>   return (\i -> do { modifyIORef n' (i+); readIORef n' })
>
> This is all related to arguments about the benefits of succinctness and
> expressivity in programming languages.
>

This is a typical red herring - a comparison slanted in favor of the lang=
uage=20
that is preferred. There's no way you're going to get an elegant solution=
 to=20
this challenge, since it requires in-place variable modification. (PG eve=
n=20
clarifies that function must perform "incremented by, not plus".)

The "right" Haskell solution is a one-liner (as mentioned in another post=
).=20
Your solution appears sound, but I get the impression that it would only=20
serve to emphasize the "limitations" of a functional approach (as was see=
n=20
recently in a similarly ridiculous thread on comp.lang.functional).

=09- j

--=20
The river is moving.
The blackbird must be flying.