0
デッキとは異なる手の最大セットを構築する関数を作成しようとしています。私はGHCiの中に私のコードをコンパイルすると、それは次のエラーを与える与えられたデッキから最大の別個の手を構築する関数を作成する
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']
与えデッキから撮影することができ、すべての可能な5枚のカードの手を与える関数のallHandsを作った:
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)’
私はどのようにこれを修正するか分からない人は助けることができますか?
あなたの問題を再現できるように、あなたのインポートと 'Deck'と' Hand'の定義を含みます。 –
問題を関連するコア情報だけに還元しようとしていただきありがとうございます。残念ながら、あなたの最新の編集の後でさえ、私はあなたが報告した問題を作り出すために多くの変更を加えなければなりませんでした。将来、あなたの削減が重要な情報を削除していないことをテストしてください。 –