Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#9270 closed bug (invalid)

GHC HEAD accepts a manual instance decl but not equivalent TH decl

Reported by: Feuerbach Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.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

If I try to build the traverse-with-class package with GHC HEAD, I get an error:

Data/Generics/Traversable/Instances.hs:21:1:
    Illegal type constructor or class name: ‘c’
    When splicing a TH declaration:
      instance c_0 a_1 => Data.Generics.Traversable.Core.GTraversable c_0
                                                                (Data.Maybe.Maybe a_1)
    where Data.Generics.Traversable.Core.gtraverse = \f_2 x_3 -> case x_3 of
                                                                     Data.Maybe.Nothing -> Control.Applicative.pure Data.Maybe.Nothing
                                                                     Data.Maybe.Just arg_4 -> (Control.Applicative.<*>) (Control.Applicative.pure Data.Maybe.Just) (f_2 arg_4)

This code used to compile with all the previous versions. Additionally, if I replace the TH splice with the generated instance declaration (with minimal corrections to make all names resolve), it is accepted:

instance c_0 a_1 => Data.Generics.Traversable.Core.GTraversable c_0
                                                                (Maybe a_1)
    where gtraverse = \f_2 x_3 -> case x_3 of
                                                                     Nothing -> Control.Applicative.pure Nothing
                                                                     Just arg_4 -> (Control.Applicative.<*>) (Control.Applicative.pure Just) (f_2 arg_4)

Change History (2)

comment:1 Changed 4 years ago by goldfire

Resolution: invalid
Status: newclosed

The code in traverse-with-class is incorrect and should lead to exactly this error. It calls classP on a type variable c. classP is meant to make a class-predicate, and should be passed the name of a class, not a type variable. The fact that this worked previously was in error.

To be fair, using a type variable in a constraint was not possible before GHC 7.9, so the author of traverse-with-class didn't really have another choice. Now that TH supports a full variety of constraints, the code can be rewritten to use AppT and VarT instead of classP.

comment:2 Changed 4 years ago by Feuerbach

That helped, thank you!

Note: See TracTickets for help on using tickets.