Many of the Parsec combinators I use are of a type such as:
foo :: CharParser st Foo
CharParser
is defined here as:
type CharParser st = GenParser Char st
CharParser
is thus a type synonym involving GenParser
, itself defined here as:
type GenParser tok st = Parsec [tok] st
GenParser
is then another type synonym, assigned using Parsec
, defined here as:
type Parsec s u = ParsecT s u Identity
So Parsec
is a partial application of ParsecT
, itself listed here with type:
data ParsecT s u m a
along with the words:
"ParsecT s u m a is a parser with stream type s, user state type u, underlying monad m and return type a."
What is the underlying monad? In particular, what is it when I use the CharParser
parsers? I can't see where it's inserted in the stack. Is there a relationship to the use of the list monad in Monadic Parsing in Haskell to return multiple successful parses from an ambiguous parser?
GenParser is defined in terms of Parsec, not ParsecT. Parsec in turn is defined as
type Parsec s u = ParsecT s u Identity
So the answer is that when using CharParser the underlying monad is the Identity monad.