Re: FW: Haskell accumulator

2002-06-14 Thread Jon Fairbairn
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. As others have implied, the only correct answer to this is it's the wrong question. One of

FW: Haskell accumulator

2002-06-13 Thread Dominic Cooney
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

Re: FW: Haskell accumulator

2002-06-13 Thread John Meacham
I am thinking one of the following... (the first needs a type signature due to the monomorphism restriction.. i think.) foo :: Num a = a - a - a foo = (+) foo n = (n +) foo n i = n + i On Fri, Jun 14, 2002 at 08:29:55AM +1000, Dominic Cooney wrote: Paul Graham is collecting canonical

Re: FW: Haskell accumulator

2002-06-13 Thread jefu
Dominic Cooney wrote: foo n = do n' - newIORef n return (\i - do { modifyIORef n' (i+); readIORef n' }) I'm not sure such a solution should be submitted without a MASSIVE CAVEAT - that this is not pure haskell style. (I'm also not sure that it is really a legal answer since I don't