#2588: Missed suggestion with context on foralls
--------------------------+-------------------------------------------------
 Reporter:  NeilMitchell  |          Owner:             
     Type:  bug           |         Status:  new        
 Priority:  normal        |      Milestone:  6.12 branch
Component:  Compiler      |        Version:  6.9        
 Severity:  normal        |     Resolution:             
 Keywords:                |     Difficulty:  Unknown    
 Testcase:                |   Architecture:  Unknown    
       Os:  Unknown       |  
--------------------------+-------------------------------------------------
Changes (by simonpj):

  * difficulty:  => Unknown
  * milestone:  => 6.12 branch

Old description:

> 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

New description:

 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

Comment:

 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

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2588#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to