0
我想寫一個函數,從甲板構造一個最大的一組不同的手。我做了一個功能allHands,讓所有可能的5張牌手可以從給定的甲板上拍攝地點製作一個函數,從一個給定的甲板構造一組最大的不同的手
type Deck = [Card]
data Card = Card { rank :: Rank, suit :: Suit }
deriving (Eq, Ord)
data Rank = R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | J | Q | K | A
deriving (Bounded, Enum, Eq, Ord)
data Suit = S | H | D | C --spades , hearts, diamonds, clubs
deriving (Bounded, Enum, Eq, Ord, Show)
newtype Hand = Hand { unHand :: [Card] } deriving (Eq, Show)
distinctHands :: Deck -> Set Hand
distinctHands deck = foldl insert empty (allHands deck)
allHands :: Deck -> [Hand]
allHands deck = map Hand (combs 5 deck)
combs :: Int -> [a] -> [[a]]
combs 0 [] = [[]]
combs 0 xs = [[]]
combs 1 xs = map (:[]) xs
combs n xs = [ y: ys | y:xs' <- tails xs, ys <- combs (n-1) xs']
當我編譯我的GHCI代碼它提供了以下錯誤:
Couldn't match type ‘Set Hand’ with ‘Hand’
Expected type: Set Hand -> Set Hand -> Set Hand
Actual type: Hand -> Set Hand -> Set Hand
In the first argument of ‘foldl’, namely ‘insert’
Couldn't match type ‘Hand’ with ‘Set Hand’
Expected type: [Set Hand]
Actual type: [Hand]
In the third argument of ‘foldl’, namely ‘(allHands deck)’
我不知道如何解決這個任何人都可以幫忙?
包括您的進口和'甲板'和'手'的定義,以便我們可以重現您的問題。 –
感謝您爲將問題簡化爲相關核心信息所作的努力,非常感謝!不幸的是,即使在你最近的編輯之後,我必須做出很多改變才能產生你報告的問題。未來,請測試您的減少未刪除任何重要信息。 –