[Haskell-cafe] Why GHC is written in Happy and not a monadic parser library?

Jason Dagit dagitj at gmail.com
Sat Aug 3 03:20:59 CEST 2013


On Fri, Aug 2, 2013 at 5:49 PM, blackbox.dev.ml
<blackbox.dev.ml at gmail.com> wrote:
> Hi!
> Is there any specific reason why GHC is written in a parser GENERATOR
> (Happy) and not in MONADIC PARSER COMBINATOR (like parsec)?
>
> Is Happy faster / handles better errors / hase some great features or
> anything else?

One reason is that  it predates monadic parser libraries.

Pros of parser generators:
  + Static analysis of the grammar (shift/reduce conflicts, debuggers, etc)
  + More succinct definition of grammar / semantic actions (easier to
formally reason about the language)
  + Efficient parser generation
  + attribute grammars

Monadic parsers are not amenable to static analysis in the same ways.
Applicative parsers hypothetically do not have this limitation, but
none of the applicative parsers provide static analysis.

I would expect parsec to be slower than happy (although I haven't
benchmarked it).

The place where monadic parsers shine is when you don't know the
formal grammar or you can't have one.

Personally, I prefer parser generators although I think monadic
parsers have their time and place. Parsec is a wonderful replacement
to writing a recursive descent parser.

Lately, I've been modernizing the happy source code and making it so
that it better integrates with cabal. I hope this will help improve
the image of happy.

Jason




More information about the Haskell-Cafe mailing list