Opened 13 months ago

Last modified 12 months ago

#7808 new feature request

data families and TH names do not mix well (e.g. cannot use TH deriving)

Reported by: duncan Owned by:
Priority: normal Milestone: 7.8.3
Component: Template Haskell Version: 7.6.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:


lots of Haskell libraries have TH functions like:

deriveJSON :: Name -> Q [Dec]

(e.g. aeson package for deriving JSON conversion)

They're used like

data Foo = Foo This That

$(deriveJSON ''Foo)

the deriveJSON reifies the Name and expects to find that the name refers to a data type, from which it finds the data constructors and generates the appropriate code.

Now, this doesn't work when the data type we want to derive an instance for is defined using a data family:

class FooClass a where
  data Foo a

instance FooClass Bar where
  data Foo Bar = Bar This That

$(deriveJSON ''Foo Bar) -- ???

We'd like to make the type Foo Bar an instance of the class (e.g. To/FromJSON) but deriveJSON expects a Name, and there is no name for this data type, its "name" is Foo Bar but obviously that's not a TH.Name.

Of course in general a name for a type application doesn't make sense, but for data family instances what other way do we have to refer to them?

Change History (1)

comment:1 Changed 12 months ago by igloo

  • Difficulty set to Unknown
  • Milestone set to 7.8.1
Note: See TracTickets for help on using tickets.