title: Making a function that constructs a maximal set of distinct hands from a given deck
body: <p>I'm trying to write a function that constructs a maximal set of distinct hands from deck. I made a function allHands that gives all possible 5-card hands that can be taken from a given deck where   </p>
  
  <pre><code>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 -&gt; Set Hand
  distinctHands deck = foldl insert empty (allHands deck)
  
  allHands :: Deck -&gt; [Hand]
  allHands deck = map Hand (combs 5 deck)
  
  combs :: Int -&gt; [a] -&gt; [[a]]
  combs 0 [] = [[]]
  combs 0 xs = [[]]
  combs 1 xs = map (:[]) xs 
  combs n xs = [ y: ys | y:xs' &lt;- tails xs, ys &lt;- combs (n-1) xs']
  </code></pre>
  
  <p>When I compile my code in GHCi it gives the following errors:   </p>
  
  <pre><code>Couldn't match type ‘Set Hand’ with ‘Hand’
     Expected type: Set Hand -&gt; Set Hand -&gt; Set Hand
     Actual type: Hand -&gt; Set Hand -&gt; 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)’
  </code></pre>
  
  <p>I don't know how to fix this can anyone help?</p>