0
4

1 回答 1

4

In the type:

eol :: (MonadParsec e s m, Token s ~ Char) => m String

the ~ is a type equality constraint, and the MonadParsec and Token typeclasses are defined by Megaparsec. They can roughly be interpreted as follows:

  • MonadParsec e s m is an assertion that type m is a monadic parser that reads a Stream of type s and represents errors using an ErrorComponent of type e
  • Token s is the underlying type of the tokens read from stream s

So, the full type can be interpreted as: eol is a monadic parser with "return value" String that parses a stream whose tokens are Char.

For your problem, most of this can be ignored. The issue you're running into is that eol returns a String value as the result of the parse, and a String isn't a Text, so you can't make an eol (which is of type Parser String) be of type Parser Text, no matter how hard you try.

Two solutions are to ignore the unwanted String return value or, if you need it as text, convert it:

Data.Text.pack <$> eol
于 2017-06-21T17:00:25.923 回答