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

Jason Dagit dagitj at gmail.com
Sat Aug 3 22:03:17 CEST 2013


On Sat, Aug 3, 2013 at 3:36 AM, Malcolm Wallace <malcolm.wallace at me.com> wrote:
>
> On 3 Aug 2013, at 02:20, Jason Dagit 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.
>
> I'm not entirely sure this is true.  I reckon the development of applicative parser combinators (used in the implementation of the nhc12 compiler, way back in 1995 or so), is roughly contemporaneous with the development of Happy, and its use inside ghc.  (I found a release note from Sept 1997 that said ghc had just converted its interface-file parser to use Happy.)  Certainly table-driven parsers in non-functional languages go back a lot further, and functional combinator-based parsing was then the relative newcomer.

Interesting. I know the happy source has copyright dates starting in
1991, so I figured it was developed to help write ghc. Perhaps they
were using it for source parsing before they adopted it for
interface-file parsing in 1997?

> As to why ghc switched to Happy, the literature of the time suggests that generated table-driven parsers were faster than combinator-based parsers.  I'm not sure I have ever seen any performance figures to back that up however.  And with the general improvement in performance of idiomatic Haskell over the last twenty years, I'd be interested to see a modern comparison.

Another con of using parsec that I forgot to mention in my previous
email is that with Parsec you need to be explicit about backtracking
(use of try). Reasoning about the correct places to put try is not
always easy and parsec doesn't help you with the task. In my
experience, this is the main bug that people run into when using
parsec.

Jason




More information about the Haskell-Cafe mailing list