As others have mentioned, Haskell does not provide a direct means for
strict evaluation.  While the class system can be used, the trick of

f x = x | x == x

is not guaranteed to work since == methods defined by the user may not
have the desired strictness property.  I could always put

instance Eq (Foo a) where
 x == x = True

into a program to defeat the x==x strictness hack.


Staying within standard Haskell you could add a class Strict as follows:

class Strict a where
 strict :: a -> Bool   -- Use bool so that strict can be used in guards

instance Strict Bool where  -- a sample instance of strict
strict x = case x of
            True -> True
            False -> True

instance Strict a => Strict (Complex a) where  -- This is actually hyperstrict
strict (a:+b) = strict a && strict b

This would allow something like

f x | strict x = ...

Of course, you would have to build the class Strict from the ground up
since it isn't provided for built-in datatypes or derived using
`deriving', but it would work correctly.

Wheather or not the lack of strictness in the language proper is a bug
or a feature I leave to others to debate.  However, as an implementer
I can always add it to my own implementation!

   John


Reply via email to