title: Pattern matching inside lambda
body: <p>I'm learning Haskell. This is a trivial example but I'd like to understand the concept why I can't use the pattern matching inside the lambda function in the following example (i.e., why does the filterfold' function run but filterfold' gives a runtime error):</p>
  
  <pre><code>-- Runs
  filterfold' :: (a -&gt; Bool) -&gt; [a] -&gt; [a]
  filterfold' p zs = foldr (\y zs -&gt; if (p y) then y:zs else zs) [] zs
  
  -- Runtime error: Non-exhaustive patterns in lambda
  filterfold :: (a -&gt; Bool) -&gt; [a] -&gt; [a]
  filterfold p (z:zs) = foldr (\y (z:zs) -&gt; if (p y) then y:(z:zs) else (z:zs)) [] (z:zs)
  </code></pre>