[Haskell-cafe] Spot the difference!

PR Stanley prstanley at ntlworld.com
Thu Sep 20 01:30:06 EDT 2007


>     test1 n _ = 1 + n
>     test2 n = \_ -> 1 + n
>
>I don't know if it's still the case, but GHC used to compile different
>code for these at high optimisation levels.  The first was essentially
>compiled to:
>
>     test1 = \n _ -> 1+n
>
>And the second to:
>
>     test2 = \n -> let x = n+1 in \_ -> x
>
>The difference is that test1 is faster if it's usually fully applied,
>test2 is fully lazy.
Fully lazy? Can you elaborate please?
Thanks, Paul



More information about the Haskell-Cafe mailing list