1 回答
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 typem
is a monadic parser that reads aStream
of types
and represents errors using anErrorComponent
of typee
Token s
is the underlying type of the tokens read from streams
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