title: Haskell multiple bindings inside lambda
body: <p>I am new to Haskell.</p>
  
  <p>I have this code (my solution to one of the exercise from Ninety-Nine Haskell Problems)</p>
  
  <pre><code>data Structure a = Single a | Multiple (a, Int) deriving (Show) 
  
  encodeM ::(Eq a)=&gt; [a]-&gt;[Structure a]
  
  encodeM l = map(\x -&gt; (let size = length x
              --h = head x
              in if size&gt;1 then Multiple ( head x, size) else Single (head x)
              )
            ) $ group l
  </code></pre>
  
  <p>When I uncomment  "-h = head x" I get: "parse error on input `='"</p>
  
  <p>But </p>
  
  <pre><code>xxx l= let size = length l  
     h = head l
        in  size
  </code></pre>
  
  <p>works fine, why it doesn't compile when I use "let" with multiple statement inside the lambda?</p>
  
  <p>I have tried to replace let by where</p>
  
  <pre><code>encodeM2 ::(Eq a)=&gt; [a]-&gt;[Structure a]
  
  encodeM2 l = map(\x-&gt;if si&gt;1 then Multiple ( head x, si) else Single (head x)
     where si = length x)
  </code></pre>
  
  <p>but it doesn't compile as well, whats wrong with it?</p>