我正在努力学习哈斯克尔。我想从列表中删除一个元素。
这是我的代码:
import Data.List
data IllegalMove = IllegalMove deriving (Show, Eq)
data Suit = Clubs | Diamonds | Hearts | Spades deriving (Show, Eq)
data Rank = Jack | Queen | King | Ace | Num Int deriving (Show, Eq)
type Card = (Suit, Rank)
removeCard :: [Card] -> Card -> Either IllegalMove [Card]
removeCard [] card = Left IllegalMove
removeCard [cards] card
| card `elem` [cards] = Right (delete card [cards])
| otherwise = Left IllegalMove
所以当我尝试编译这个例子时我得到一个错误:
*Main> removeCard [(Clubs,King),(Diamonds,Queen)] (Clubs,Queen )
*** Exception: Assignment13.hs:(7,1)-(10,38): Non-exhaustive patterns in function removeCard