I've run into a little problem i can't seem to solve, been at it for a few hours now to no avail.
I've defined a datatype, Hand.
data Hand = Empty | Add Card Hand
deriving (Eq, Show)
And another type i'm using:
data Card = Card { rank :: Rank, suit :: Suit }
deriving (Eq, Show)
I'm trying to create an infix operator which will add two hands and return a third one.
(<+) :: Hand -> Hand -> Hand
(<+) (Add c1 h1) (empty) = (Add c1 h1)
(<+) hand1 (Add c2 hand2) = (Add c2 (hand1 <+ hand2))
When i run a quickcheck test on this to see wether it's associative or not i get an error after a few times. The error says:
BlackJack.hs:(71,1)-(72,53): Non-exhaustive patterns in function <+
The three arguments it returns to me are empty (Always this one as the first one) and then a large hand as a second and the third argument. For example:
Also, quickchest test looks something like
((hand1 <+ hand2) <+ hand3) == (hand1 <+ (hand2 <+ hand3))
.
I'm guessing i've got not enough cases to handle every possible scenario? I just can't figure out what's gone wrong. :(
Please no direct solutions, hints will do!
Edit: Did as a helpful commenter suggested and added a case for when two hands are empty, which returns the empty hand. All works well now. :) And to clear up confusion, i had declared what a empty hand is earlier. Empty and empty are two defferent things in my code, and i used them 'correctly'. :)