title: Example of simple parsers in haskell
body: <p>I have the following parsers functions </p>
  
  <pre><code>import Data.Char
  type Parser a = String -&gt; [(a,String)]
  
  return' :: a -&gt; Parser a
  return' v = \inp -&gt; [(v,inp)]
  
  failure :: Parser a
  failure = \inp -&gt; []
  
  item :: Parser Char
  item = \inp -&gt; case inp of
           [] -&gt; []
       (x:xs) -&gt; [(x,xs)]
  
  parse :: Parser a -&gt; String -&gt; [(a,String)]
  parse p inp = p inp
  
  parse :: Parser a -&gt; String -&gt; [(a,String)]
  parse p inp = p inp
  
  (+++) :: Parser a -&gt; Parser a -&gt; Parser a
  p +++ q = \inp -&gt; case parse p inp of
              [] -&gt; parse q inp
       [(v,out)] -&gt; [(v,out)]
  </code></pre>
  
  <p>So far so good, they can be loaded into ghci. But when I add the following function</p>
  
  <pre><code>sat :: (Char -&gt; Bool) -&gt; Parser Char
  sat p = do x &lt;- item
             if p x then return x else failure
  </code></pre>
  
  <p>I obtain an error. Could you tell what's going on?</p>