ParseError不在范围内 - “48小时内的方案”

时间:2014-08-03 07:43:29

标签: haskell ghc parsec

(noob alert)我正在经历Write yourself a Scheme in 48 hours;但是在编译与Ch.4,错误检查和异常有关的代码时,我得到一个“不在范围内:ParseError”消息(按照教程1:1,不需要在这里重复)。 我使用GHC 7.6.3。 导入部分:

import Control.Monad
import Text.ParserCombinators.Parsec hiding (spaces)

但我也尝试添加import Text.ParserCombinators.Parsec.Errorimport Text.Parsec.Error,但无济于事。 似乎ParseError ADT由几个不同的库公开,但由于某种原因,编译器没有看到它。其他Parsec功能可以正常工作。

任何指针?提前谢谢

1 个答案:

答案 0 :(得分:1)

修复来自于替换一个函数声明中的变量名:

WRONG:

showError :: LispError -> String
showError (UnboundVar msg varname) = msg ++ ": " ++ varname
showError (BadSpecialForm msg frm) = msg ++ ": " ++ show frm
showError (NotFunction msg f) = msg ++ ": " ++ show f
showError (NumArgs expected found) = "Expected " ++ show expected ++ " args: found values     " ++ unwordsList found
showError (TypeMismatch expected found) = "Invalid type: expected " ++ expected ++ ", found " ++ show found
showError (ParseError pe) = "Parse error at " ++ show pe

RIGHT:

showError :: LispError -> String
showError (UnboundVar message varname) = message ++ ": " ++ varname
showError (BadSpecialForm message form) = message ++ ": " ++ show form
showError (NotFunction message func) = message ++ ": " ++ show func
showError (NumArgs expected found) = "Expected " ++ show expected 
                              ++ " args: found values " ++ unwordsList found
showError (TypeMismatch expected found) = "Invalid type: expected " ++ expected
                                   ++ ", found " ++ show found
showError (Parser parseErr) = "Parse error at " ++ show parseErr

我发誓,我不明白。任何澄清都将受到高度赞赏。