[Haskell-cafe] Re: Eta-expansion destroys memoization?

Derek Elkins derek.a.elkins at gmail.com
Tue Oct 12 06:14:59 EDT 2010


On Tue, Oct 12, 2010 at 4:34 AM, Bertram Felgenhauer
<bertram.felgenhauer at googlemail.com> wrote:
> Simon Marlow wrote:
>> Interesting.  You're absolutely right, GHC doesn't respect the
>> report, on something as basic as sections!  The translation we use
>> is
>>
>>   (e op)  ==>  (op) e
>>
>> once upon a time, when the translation in the report was originally
>> written (before seq was added) this would have been exactly
>> identical to \x -> e op x, so the definition in the report was
>> probably used for consistency with left sections.
>>
>> We could make GHC respect the report, but we'd have to use
>>
>>   (e op)  ==>  let z = e in \x -> z op x
>>
>> to retain sharing without relying on full laziness.
>
> We should keep in mind that this was changed deliberately in ghc 6.6,
> in order to support "postfix" operators.
>
>    http://www.haskell.org/ghc/docs/6.6/html/users_guide/release-6-6.html
>
> The motivating example was the factorial operator which can currently
> be written as  (n !)  in ghc-Haskell.

>From http://www.haskell.org/ghc/docs/6.6/html/users_guide/syntax-extns.html#postfix-operators
"Since this extension goes beyond Haskell 98, it should really be
enabled by a flag; but in fact it is enabled all the time. (No Haskell
98 programs change their behaviour, of course.) "

Which is not true, but is probably true enough.

Of course, there is now a flag
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/syntax-extns.html#postfix-operators
but it seems that the non-standard interpretation of (e !) is still
kept even without it.  Without the flag, it type checks as if you had
written \x -> e ! x but it still behaves as if you had written (!) e.


More information about the Haskell-Cafe mailing list