[Haskell-cafe] Re: A better syntax for qualified operators?

Simon Marlow simonmarhaskell at gmail.com
Wed Oct 18 11:42:00 EDT 2006

Brian Hulley wrote:

> When you try to write an editor for Haskell (or some subset of it), you 
> quickly discover these areas of Haskell syntax like the above which need 
> to be changed to get an optimum interactive editing experience. I think 
> it *is* possible to adjust the Haskell grammar so that it is LL(1) and 
> the only reason it is not already LL(1) seems to be that the grammar has 
> been designed with compilers (which only need to deal with complete 
> modules) in mind rather than programmers interactively editing in mind.
> (The other change needed for LL(1) is to give contexts a marker before 
> they appear eg:
>        foo :: {MonadIO m} a -> m a
> )

Just catching up on haskell-cafe...

The other notorious part of the Haskell grammar that isn't LL/LR(1) is 
expressions vs. patterns.  In a statement, if you see a variable, you don't know 
whether it is a pattern variable (apat) or an expression variable (aexpr).  This 
is why Haskell grammars generally parse expressions and patterns using the same 

> By LL(1) I'm really meaning that the grammar for interactive editing 
> needs to be adjusted so that it is possible to maintain the invariant 
> that as code is entered from left to right constructs and identifiers 
> can be highlighted according to their grammatical role and highlighting 
> (modulo incompleteness) must remain unchanged regardless of whatever is 
> typed afterwards to the right otherwise it can become more of a 
> liability than a help, hence my hope that some future revision of 
> Haskell grammar might consider taking the above points into account.

So you won't be able to colour patterns differently from expressions, that 
doesn't seem any worse than the context vs. type issue.  Indeed, I'm not even 
sure you can colour types vs. values properly, look at this:

   data T = C [Int]

at this point, is C a constructor?  What if I continue the declaration like this:

   data T = C [Int] `F`

now it's a type!


More information about the Haskell-Cafe mailing list