gpt4 book ai didi

haskell - 使用 Parsec 输入错误

转载 作者:行者123 更新时间:2023-12-04 05:45:39 24 4
gpt4 key购买 nike

我正在使用 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 produces a type error我尝试添加 NoMonomorphismRestriction language pragma,但这并没有帮助。

我承认,我发现 Parsec 的学习曲线非常陡峭,即使我有一些 Haskell 经验。 Real World Haskell 书中的示例基于 Parsec 2,这无济于事。

最佳答案

您正在编写此代码:

many char ' '

这会将 2 个参数传递给 many功能: char' ' .你要做的是传递 char ' '的结果到 many函数,它是这样完成的:
many (char ' ')

关于haskell - 使用 Parsec 输入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10725031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com