我正在使用 Parsec 3.1.2 和 GHC 7.4.1 来尝试为有点毛茸茸的数据文件格式编写解析器。我认为这是一个非常微不足道的案例,但我遇到了类型错误。我正在尝试遵循 Real World Haskell 中的应用函子示例。
import Text.ParserCombinators.Parsec hiding (many, optional, (<|>))
import Text.ParserCombinators.Parsec.Char
import Text.Parsec.String
import Control.Applicative
p_int = many char ' ' *> many1 digit <* many char ' '
现在,最初我收到以下类型错误:
Couldn't match expected type `[Char]'
with actual type `Text.Parsec.Prim.ParsecT s0 u0 m0 [a0]'
In the return type of a call of `many1'
In the second argument of `(*>)', namely `many1 digit'
In the first argument of `(<*)', namely
`many char ' ' *> many1 digit'
基于Trivial parsec example 产生类型错误我尝试添加NoMonomorphismRestriction
语言 pragma,但这没有帮助。
我承认,我发现 Parsec 的学习曲线相当陡峭,尽管我有一点 Haskell 经验。Real World Haskell 书中的示例基于 Parsec 2 并没有帮助。