[Haskell-beginners] Ord and Eq instances for complex types

Mike Meyer mwm at mired.org
Wed Oct 19 02:29:24 CEST 2011


Ok, *this* works just fine:

data Hand = HighCard {cards :: [Card]}
          | PairOf {rank1 :: Rank, cards :: [Card]}
          | TwoPair {rank1, rank2 ::Rank, cards :: [Card]}
          | ThreeOfAKind {rank1 :: Rank, cards :: [Card]}
          | Straight {cards :: [Card]}
          | Flush {cards :: [Card]}
          | FullHouse {rank1, rank2 :: Rank, cards :: [Card]}
          | FourOfAKind {rank1 :: Rank, cards :: [Card]}
          | StraightFlush {cards :: [Card]}
            deriving (Show, Eq, Ord)

The derived order is actually correct - providing, again, that the hands are
well-formed (which the unshown constructor makeHand :: [Cards] -> Hand
insures). The only writeup I could find for deriving Ord for datatypes was
the report. Anyone got a better pointer to one?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111018/d5fcc900/attachment.htm>


More information about the Beginners mailing list