ApplicativeDo语言扩展与`Parsing` applicative仍在寻找Monad实例

Asa*_*Asa 11 haskell ghc applicative

我想写使用一个解析器parsers 使用do的语法.这是一个例子:

{-# LANGUAGE ApplicativeDo #-}
import Text.Parser.Char (string, spaces)
import Text.Parser.Token (TokenParsing, natural)

issueParser :: TokenParsing p => p Integer
issueParser = do
  spaces
  string "**Issue:**"
  spaces
  string "https://github.com" <|> string "github.com"
  string "/commercialhaskell/stack/issues/"
  natural
Run Code Online (Sandbox Code Playgroud)

GHC给我的错误是Could not deduce (Monad p) arising from a do statement from the context: TokenParsing p.此错误消息是正确的,TokenParsing不提供Monad作为超类,但它确实提供了Applicative哪些方法,因为我打开了这个语言扩展,我应该能够使用do语法Applicative.我在做错了什么/在这里失踪了?

Asa*_*Asa 14

弄清楚了.要使此示例在ghc 8.0.2上运行,您需要添加下划线生成器,如下所示:

{-# LANGUAGE ApplicativeDo #-}
import Text.Parser.Char (string, spaces)
import Text.Parser.Token (TokenParsing, natural)

issueParser :: TokenParsing p => p Integer
issueParser = do
  _ <- spaces
  _ <- string "**Issue:**"
  _ <- spaces
  _ <- string "https://github.com" <|> string "github.com"
  _ <- string "/commercialhaskell/stack/issues/"
  n <- natural
  pure n
Run Code Online (Sandbox Code Playgroud)

这里已经有一个ghc bug来解决这个问题:https://ghc.haskell.org/trac/ghc/ticket/12666