Scott Michel | 28 Apr 07:24
Picon

Chimeric syntax

I've been hacking along on a NetBeans Haskell plugin (*) Looking at
Parser.y.pp, because both Eclipse and NetBeans work with antlr, it
seems like there are interesting cases in which chimeric constructions
parse correctly. Here's an example:

class ParsedModule m where
  let { a = 1; b = 2; } in a + b :: Int :: Int

This is mostly accepted by ghc, which complains with an invalid type signature.

This got me to thinking that either ghc has issues or I have some
fundamental misunderstanding of Haskell syntax. Or, maybe I should use
someone else's grammar.

-scooter

(*) Don't tell me about eclipsefp2: I know already. It's the Monty
Python parrot of Haskell IDE support. And the code is about as
Teutonic as one can get. :-)
Max Bolingbroke | 28 Apr 22:09
Picon
Favicon
Gravatar

Re: Chimeric syntax

2009/4/28 Scott Michel <scooter.phd <at> gmail.com>:

> This got me to thinking that either ghc has issues or I have some > fundamental misunderstanding of Haskell syntax. Or, maybe I should use > someone else's grammar.
GHC's parser is over-generous by design. See http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser. A precise description of what is valid Haskell it is certainly NOT, but it will certainly accept any valid Haskell program. This may not be quite what you want for an IDE - but it might be good enough for a first cut. Cheers, Max
Scott Michel | 29 Apr 04:33
Picon

Re: Chimeric syntax

On Tue, Apr 28, 2009 at 1:09 PM, Max Bolingbroke
<batterseapower <at> hotmail.com> wrote:

> 2009/4/28 Scott Michel <scooter.phd <at> gmail.com>: >> This got me to thinking that either ghc has issues or I have some >> fundamental misunderstanding of Haskell syntax. Or, maybe I should use >> someone else's grammar. > > GHC's parser is over-generous by design. See > http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser. A > precise description of what is valid Haskell it is certainly NOT, but > it will certainly accept any valid Haskell program. This may not be > quite what you want for an IDE - but it might be good enough for a > first cut.
Actually, given what ghc will accept, I seriously doubt that the LR grammar can ever successfully translate to a LL(*) grammar. Liberal, it may be, but it probably should be valid. I just followed the current parser rules to their ultimate conclusion. I suspect that people would be quite surprised by what Parser.y.pp will actually accept. Basically, my understanding is that a 'let' should not be allowed in a 'class' declaration and yet, ghc is quite happy to allow it. So my understanding is correct, but ghc grammar is (perhaps) too flexible. -scooter PS: Anyone got a multicore Haskell experience they want to share at Supercomputing this year? The guys from Galois did a great job shocking the audience last year.
Picon
Favicon

Re: Chimeric syntax


On Apr 28, 2009, at 01:24 , Scott Michel wrote:

> I've been hacking along on a NetBeans Haskell plugin (*) Looking at > Parser.y.pp, because both Eclipse and NetBeans work with antlr, it > seems like there are interesting cases in which chimeric constructions > parse correctly. Here's an example: > > class ParsedModule m where > let { a = 1; b = 2; } in a + b :: Int :: Int > > This is mostly accepted by ghc, which complains with an invalid type > signature.
Looking at the Online Report, my guess is it parses as: exp^0 = "let {a = 1; b = 2; } in a + b" type = "Int :: Int" and of course "Int :: Int" is an invalid type signature. (::) parses as if it were a very low precedence operator. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery <at> kf8nh.com system administrator [openafs,heimdal,too many hats] allbery <at> ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Gmane