Haskell: Parsing error with 'where' and a guard

haskell, syntax-error

Solution

Try:

step acc ch
    | isDigit ch = if res < acc then error "asInt_fold: result overflowed" else res
    | otherwise  = error ("asInt_fold: not a digit " ++ (show ch))
    where res = 10 * acc + (digitToInt ch)

Problem

So, I'm just starting to teach myself Haskell out of the book Real World Haskell, and in the course of doing one of the exercises, I wrote the following code: ``` step acc ch | isDigit ch = if res < acc then error "asInt_fold: \ \result overflowed" else res where res = 10 * acc + (digitToInt ch) | otherwise = error ("asInt_fold: \ \not a digit " ++ (show ch)) ``` When I loaded it into GHCi 6.6, I got the following error: ``` IntParse.hs:12:12: parse error on input `|' Failed, modules loaded: none. ``` I'm virtually certain that the error is due to the interaction of the "where" clause and the subsequent guard; commenting out the guard eliminates it, as does replacing the "where" clause with an equivalent "let" clause. I'm also pretty sure that I must have mangled the indentation somehow, but I can't sort out how. Thanks in advance for any tips.

Original source