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 = 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 language
that is preferred. There's no way you're going to get an elegant solution to
this challenge, since it requires in-place variable modification. (PG even
clarifies that function must perform "incremented by, not plus".)
The "right" Haskell solution is a one-liner (as mentioned in another post).
Your solution appears sound, but I get the impression that it would only
serve to emphasize the "limitations" of a functional approach (as was seen
recently in a similarly ridiculous thread on comp.lang.functional).
- j
--
The river is moving.
The blackbird must be flying.
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell