【发布时间】:2014-06-17 12:23:21
【问题描述】:
尝试在这里编译 Haskell.Happy 示例:http://www.haskell.org/happy/doc/html/sec-using.html#sec-other-datatypes,在生成 .hs 文件后,我得到了
No instance for (Show ([String, Int)] -> Int
错误,正在尝试编译它,而示例的第一部分已编译并运行良好
我做错了什么?
编辑:完整的错误消息
No instance for (Show ([(String, Int)] -> Int))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show ([(String, Int)] -> Int))
In the first argument of `(.)', namely `print'
In the second argument of `(>>=)', namely `print . calc . lexer'
In the expression: getContents >>= print . calc . lexer
我在跑步
ghc example.hs
而这条线是
main = getContents >>= print . calc . lexer
可能重复的问题的答案是传递一个环境,但我怎么能在这里做呢?
【问题讨论】:
-
我认为链接的答案是正确的,但这意味着 Happy 文档中存在错误。在
ghci中加载您的example.hs并询问calc是什么类型(:t calc)。我怀疑你会发现它需要一个不满足的[(String, Int)]参数。