On Tue, 26 Sep 2000, Ch. A. Herrmann wrote:
>     John> write (x==x) `seq` y 
> I'm heavily confused here.
> What happens, if 
> 
>    (a) an optimizer replaces (x==x) by True?
>        If the optimizer is not permitted to do that,
>        its power appears to be limited severely.

Remember that (==) in Haskell is just a method of the Eq class - it is not
semantic equality. Nothing prevents users from defining their own
instances for (==) and these instances need not satisfy any reasonable
equality laws. 

Anyway, using (x==x) as a hyperstrict seq is a hack, a useful and mostly
working hack, but not guaranteed to work in all cases. A more reliable
hyperseq can be implemented as a class method for a new class with
instances for all types you want to use it on. I believe this method and
this class were the reasons for implementing DrIFT (search for the class
NFData).

  http://www.dcs.gla.ac.uk/~nww/Derive/derivehome.html

/Patrik Jansson



Reply via email to