So, I am just starting to teach myself Haskell from the book Real World Haskell, and in the course of performing 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 downloaded it in GHCi 6.6, I received the following error:
IntParse.hs:12:12: parse error on input `|'
Failed, modules loaded: none.
I am pretty sure that the error is due to the interaction of the where clause and the subsequent guard; commenting out the protection removes it, and replaces the where clause with the equivalent let clause. I am also sure that I somehow distorted the indentation, but I cannot figure out how to do this.
Thanks in advance for any advice.
source
share