Opened 9 years ago

Closed 5 years ago

#2588 closed bug (fixed)

Missed suggestion with context on foralls

Reported by: NeilMitchell Owned by:
Priority: lowest Milestone: 7.6.2
Component: Compiler Version: 6.9
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)

Given the program:

module Test where
test :: forall a . a -> a
test = id

I get the nice and helpful error message:

Test.hs:3:17:
    Illegal operator `.' in type `forall a . (a -> a)'
      Perhaps you intended to use -XRankNTypes or similar flag
      to enable explicit-forall syntax: forall <tvs>. <type>

[I personally usually want ScopedTypeVariables rather than RankNTypes, but its still a very useful hint at where to look]

However, trying the program:

module Test where
test :: forall a . Eq a => a -> a
test = id

Gives:

Test.hs:3:24: parse error on input `=>'

I think it would be helpful to give the same suggestion as above.

-- Neil

Change History (14)

comment:1 Changed 9 years ago by simonpj

Description: modified (diff)
difficulty: Unknown
Milestone: 6.12 branch

Good suggestion, but harder to implement. Without ScopedTypeVariables, forall is not a keyword, so GHC is trying to parse that thing as a type, and it just doesn't follow the syntax for types.

The solution is probably this:

  • Do not treat => specially in the parser
  • Instead parse it as an infix operator
  • In the post-parsing re-organisation (RdrHsSyn), unswizzle the => into a constraint set
  • But in doing so, if the stuff on the left of the => doesn't look like a constraint set, look for a leading forall and complain appropriately

Not really hard, but fiddly.

Simon

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by SamB

Why not just warn whenever forall is parsed as a type variable? It's a very odd name for a type variable anyway.

comment:5 Changed 9 years ago by simonpj

Good idea. would work nicely for

  f :: forall -> forall

The difficulty is that the parser reports a parse error in your example, and errors trump warnings.

So I'm still not sure how to do this neatly.

Simon

comment:6 Changed 7 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:7 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:8 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:9 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:10 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:11 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:12 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:13 Changed 5 years ago by monoidal

Type of failure: None/Unknown

It seems this bug is fixed in 7.6. Both

test :: forall a . a -> a

and

test :: forall a . Eq a => a -> a

currently give the same error message, suggesting RankNTypes. Close as fixed?

comment:14 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed

Yes, it does look ok now. I'm not quite sure why it's ok now, but I'm happy. I'll close the ticket.

Simon

Note: See TracTickets for help on using tickets.