Nikolay Metchev wrote:
data Face = Ace | Two | Three | Four | Five | Six | Seven | Eight | Nine
| Ten | Jack | Queen | King deriving (Enum, Show, Eq)
listComparator :: (Eq a) => [a] -> a -> a -> Ordering
listComparator xs a b = compare x y
where
x = elemIndex a xs
y = elemIndex b xs
fourOfAKindBonusFaceOrder :: [Face]
fourOfAKindBonusFaceOrder = [Queen, King, Ten, Ace, Nine, Jack]
Add:
newtype FourOfAKindBonusFace = FKBF Face deriving Eq
instance Ord FourOfAKindBonusFace where
compare (FKBF x) (FKBF y) =
listComparator fourOfAKindBonusFaceOrder x y
Henceforth you can do these in the four-of-a-kind order:
FKBF Queen >= FKBF Ten
FKBF Ten <= FKBF Queen
compare (FKBF Ten) (FKBF Queen)
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe