title: Is it possible to nest guards in Haskell?
body: <p>Haskell newbie here, trying to write code to parse math expressions.
  Code:</p>
  <pre><code>isDigit :: Char -&gt; Bool
  isDigit c = c &gt;= '0' &amp;&amp; c &lt;= '9'
  
  parseNumber :: String -&gt; Maybe (String, String)
  parseNumber [] = Just (&quot;&quot;, &quot;&quot;)
  parseNumber (h:ls)
      | isDigit h
          | p == Nothing = Just([h], ls)      -- Digit found    &lt;&lt;&lt; ERROR!!
          | otherwise = Just (h:fst d, snd d) -- Ends in a digit
      | h == '.'
          | p == Nothing = Nothing                                -- Ends in a point
          | not ('.' `elem` (snd d)) = Just (h:(fst d), snd d)    -- We don't want multiple dots
      | otherwise = Nothing       -- Not a number, stop looking!
      where 
          p = parseNumber ls
          Just d = parseNumber ls -- Float version of p. Not used if p is Nothing  
  </code></pre>
  <p>This function is supposed to take a string that starts with a number, and returns the number separated from the rest of the expression. Example:</p>
  <blockquote>
  <p>parseNumber &quot;123.0 + 2&quot;</p>
  <p>(&quot;123.0&quot;, &quot; + 2&quot;)</p>
  </blockquote>
  <p>I think this nested guards' syntax reads really nicely, but it doesn't work.
  The error reads, for the marked line:</p>
  <blockquote>
  <p>parse error on input `|'</p>
  </blockquote>
  <p>Are chained guards not allowed in Haskell? Or am I writting this wrongly somehow? Also, what alternatives do I have to chain logic in a simple way?</p>