【发布时间】:2009-08-22 15:23:05
【问题描述】:
所以,我刚刚开始从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”子句一样。我也很确定我一定是以某种方式破坏了缩进,但我不知道是怎么回事。
提前感谢您的任何提示。
【问题讨论】:
标签: haskell syntax-error