Opened 10 years ago

Last modified 4 years ago

#3766 new bug

Parsing of lambdas is not consistent with Haskell'98 report.

Reported by: lilac Owned by:
Priority: low Milestone:
Component: Compiler (Parser) Version: 6.10.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Consider the following expression:

(\x -> x :: Int . id)

GHC (without any -X flags) currently reports a parse error:

Illegal operator .' in type Int . id'
Use -XTypeOperators to allow operators in types

However, I think this expression is legal in Haskell'98 (and indeed still legal in Haskell 2010). The report gives an (ambiguous) expression grammar, which (unambiguously) parses the above as (\x -> (x :: Int)) . id. The report further says that lambdas extend as far as possible to the right, but the parse which GHC is using is not a possible parse according to the grammar, since infix operators (other than "->") are not allowed in the construction 'type'.

That said, I'd much rather see this fixed in the Haskell 2011 report than in GHC :)

Change History (13)

comment:1 Changed 10 years ago by lilac

Correction: the Report's grammar admits two parses: (\x -> (x :: Int)) . id, and ((\x -> x) :: Int) . id; the "as far to the right as possible" rule picks the former.

comment:2 Changed 10 years ago by lilac

Amusingly, with any extension which adds the 'forall x . y' syntax to types (such as -XExistentialQuantification) enabled, the expression is accepted! Cases with other operators, such as (\x -> x :: Int $ 4) still fail, however.

comment:3 Changed 10 years ago by lilac

The same issue also affects the other two "as far to the right as possible" cases; these are both incorrectly rejected:

let in id :: Int -> Int $ 4
if False then id else id :: Int -> Int $ 4

comment:4 Changed 10 years ago by igloo

Milestone: 6.14.1

Thanks for the report. We should either fix GHC or get an H' proposal written.

comment:5 Changed 9 years ago by igloo

Milestone: 7.0.17.0.2

comment:6 Changed 9 years ago by igloo

Milestone: 7.0.27.2.1

comment:7 Changed 8 years ago by igloo

Milestone: 7.2.17.4.1

comment:8 Changed 8 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:9 Changed 7 years ago by igloo

Milestone: 7.6.17.6.2

comment:10 Changed 5 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:11 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:12 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:13 Changed 4 years ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.