[Haskell-cafe] Cute code [was: The C Equiv of != in Haskell miscommunication thread]

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue May 29 08:19:31 EDT 2007


On Tue, May 29, 2007 at 12:15:23PM +0200, Vincent Kraeutler wrote:
> Donald Bruce Stewart wrote:
> > P.S. Have some cute code:
> >
> >     Control.Monad.Fix.fix ((1:) . scanl (+) 1)
> 
> this is cute indeed! (do you keep an emergency reserve of those around
> for situations like this? ;-))
> 
> ever the interested amateur, i admittedly remain stumped by fix (there's
> evidence i'm not the only one [1])

The above code is equivalent to

    let l = 1 : scanl (+) 1 l in l

which is a bit easier to decipher.

The rest is maths and the subtleties of lazy evaluation.

Best regards
Tomek


More information about the Haskell-Cafe mailing list