John Meacham john at
Tue May 13 22:11:16 UTC 2014

On Tue, May 13, 2014 at 2:22 PM, Ian Lynagh <igloo at> wrote:
> It's based on your code, but I had to essentially completely re-write it
> to work with the way that GHC's parser works; I don't think sharing the
> code will be feasible.

Ah, yeah, I didn't think the code would translate directly, but I'd want the
logic to match of course.

But on that subject of sharing code, I just relicensed jhc under a
permissive license like ghc with the last release so code can move both
ways. I mainly think it will be useful in the libraryies and support
routines rather than compiler core stuff. though, I may nab the c--
parser/emitter. I already use it as an intermediate language but with no
external representation.

My lexer/parser is based on a branch of the thih
source which also eventually begat haskell-src but it is fairly hairy.
Written before monad syntax so has hand written CPS everywhere. I am hoping
that if the new layout rule works I can move to a packrat or hybrid
recursive descent parser, letting LALR handle the gross structure but use
hand written recursive descent with excellent error messages for
expressions. The only reason I have stuck it out with the happy one for so
long is it has the magic lexer/layout interaction baked in.

> I also fixed some bugs (e.g. I think that with your code,
> Â  Â  foo = let { x = x }
> Â  Â  Â  Â  Â  in x
> turns into something like
> Â  Â  foo = let { x = x }
> Â  Â  Â  Â  Â  } in x
> ) and made some tweaks after trying it on GHC+bootlibs, but I don't have
> details to hand.

ah cool, can you point me to which file it is implemented in in the source
so I can copy your new rules?

> However, the consensus was that the new rule has too many cases, due to
> trying to match the old rule as closely as possible, and despite that it
> doesn't have the advantage that it is a drop-in replacement. ISTR Cabal
> in particular needed several changes to compile with it
> (0aba7b9f2e5d8acea156d575184a4a63af0a1ed3). Most of them were code of
> the form
> Â  Â  case e of
> Â  Â  p -> e'
> Â  Â  where bs
> needing the 'where' clause to be less indented.

Hmm.. interesting. I only tested against the whole nofib suite originally. I
need to expand that.

> The plan, yet to be implemented, was to remove some of the cases of the
> new rule, making it easier to understand, specify and implement, at the
> expense of breaking more code when the switch is flipped.

I don't mind that if it makes sense. Would only work if ghc did it though as
no one is going to relayout their code for jhc (unless they are one of the
ones using it to compile to ARM boards with 32k of RAM :) ).

Maybe I can twiddle the algorithm in ghc itself for a bit first to take
advantage of the bigger accessible codebase to test on.

> Ideally, there would be a period during which compilers would check
> during compilation whether the new rule would give a different token
> sequence to the old rule, and warn if so.

Yeah, it would be tricky in jhc to support both front ends, though... maybe
I can revert my current lexer parser back to simpler haskell 98 syntax and
require anything that uses extensions to use the new layout rule.


John Meacham -

More information about the Glasgow-haskell-users mailing list