所以,我刚开始从Real World Haskell书里自学 Haskell ,在做其中一个练习的过程中,我写了以下代码:
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))
当我将其加载到 GHCi 6.6 中时,出现以下错误:
IntParse.hs:12:12: parse error on input `|'
Failed, modules loaded: none.
我几乎可以肯定该错误是由于“where”子句和后续守卫的相互作用造成的;注释掉守卫会消除它,就像用等效的“let”子句替换“where”子句一样。我也很确定我一定是以某种方式破坏了缩进,但我无法弄清楚如何。
提前感谢您的任何提示。