在haskell中使用oneOf,编译错误

发布于 2024-08-17 11:15:44 字数 681 浏览 4 评论 0原文

我是 Haskell 的新手。 我正在尝试编译我下载的这个 Haskell 文件,但它给了我一些错误。

No instance for (Text.Parsec.Prim.Stream s m Char)
  arising from a use of 'letter' at Parse.lhs:649:26-31
Possible fix:
  add an instance declaration for (Text.Parsec.Prim.Stream s m Char)
In the first argument of '(<|>)', namely 'letter'
In the expression: letter <|> oneOf "_"
In the definition of 'firstAllowed':
  firstAllowed = letter <|> oneOf "_"

不确定这是否足够,但这是有错误的代码部分:

parseIdent = do { str <- indent
                ; return (makeIdent str)
                } <?> "identifier"
  where firstAllowed = oneOf "_" <|> letter

I'm a complete newbie at Haskell.
I'm trying to compile this Haskell file I've downloaded but it's giving me some errors.

No instance for (Text.Parsec.Prim.Stream s m Char)
  arising from a use of 'letter' at Parse.lhs:649:26-31
Possible fix:
  add an instance declaration for (Text.Parsec.Prim.Stream s m Char)
In the first argument of '(<|>)', namely 'letter'
In the expression: letter <|> oneOf "_"
In the definition of 'firstAllowed':
  firstAllowed = letter <|> oneOf "_"

Not sure if this is enough, but here's the section of the code with the error:

parseIdent = do { str <- indent
                ; return (makeIdent str)
                } <?> "identifier"
  where firstAllowed = oneOf "_" <|> letter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-08-24 11:15:44

在您引用的部分中,本地 firstAllowed 函数似乎没有在任何地方使用。如果删除 where 行会发生什么?

或者,您可以尝试将此类型签名添加到 firstAllowed

 where
    firstAllowed :: Stream s m Char => ParsecT s u m Char
    firstAllowed = ...

In the part you quoted the local firstAllowed function doesn't seem to be used anywhere. What happens if you remove the where line?

Alternatively you could try to add this type signature to firstAllowed:

 where
    firstAllowed :: Stream s m Char => ParsecT s u m Char
    firstAllowed = ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文