[Haskell-beginners] Why does this Ord-class instance crash?

R J rj248842 at hotmail.com
Fri May 21 08:13:41 EDT 2010

I'm trying to declare Triangle as an instance of the Ord class without using "deriving (Ord)", so I can better understand the manual instantiation.
As I understand it, all I need merely to define "<".  Yet, when I do so using the code snippet below, this code hangs when I type "Scalene > Failure" in GHCi.  Why is that, and what's the fix?  Thanks.
data Triangle                  =  Failure                               |  Equilateral                               |  Isosceles                               |  Scalene                               deriving (Eq, Show)
instance Ord Triangle where    Failure     < Failure      = False    Failure     < _            = True
    Equilateral < Failure      = False    Equilateral < Equilateral  = False    Equilateral < _            = True
    Isosceles   < Scalene      = True    Isosceles   < _            = False
    Scalene     < _            = False
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100521/abab04c9/attachment.html

More information about the Beginners mailing list