如何从列表中删除元素

时间:2015-02-08 15:14:22

标签: haskell

我正在努力学习哈斯克尔。我想从列表中删除一个元素。

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

导入Data.List。并使用Hoogle