[Haskell] bug in language definition (strictness)
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Thu Aug 6 06:08:12 EDT 2009
It has been brought to my attention (as errata editor of the revised
H'98 report) that there is a bug in the language definition,
concerning strictness annotations on datatypes.
In section 4.2.1, the translation of strict components of a data
constructor is defined as
> (\ x1 ... xn -> ( ((K op1 x1) op2 x2) ... ) opn xn)
>
> where opi is the non-strict apply function $ if si is of the form
> ti, and opi is the strict apply function $! (see Section 6.2) if si
> is of the form ! ti. Pattern matching on K is not affected by
> strictness flags.
>
yet, because of the definition of $!, this applies the constructor to
its arguments right-to-left instead of the intuitive left-to-right.
All extant compilers in fact evaluate the strict fields left-to-right
in violation of the Report.
The same non-intuitive behaviour can be seen more clearly in the
simple expression:
(f $! x) $! y
in which you might expect x to be evaluated before y, but in fact it
is the other way round. (And here, the compilers do follow the Report.)
The fix I propose for H'98 (and equally for Haskell Prime) is to
change the definition of $! as follows
Replace
f $! x = x `seq` f x
with
f $! x = f `seq` x `seq` f x
in section 6.2
Regards,
Malcolm
More information about the Haskell
mailing list