Opened 22 months ago

Closed 21 months ago

Last modified 18 months ago

#14748 closed feature request (wontfix)

Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int))

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler Version:
Keywords: QuantifiedConstraints, deriving 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

(based on WIP -XQuantifiedConstraints)

Could GHC infer the context for deriving Data (Foo f) (#12245)?

data Foo f = Foo (f Bool) (f Int)
  deriving stock Data

{-
Generates:

instance (Typeable f, (forall xx. Data xx => Data (f xx))) => Data (Foo f)
-}

Change History (4)

comment:1 Changed 22 months ago by simonpj

Keywords: deriving added

I'm not sure. When doing

data T a = MkT a [a] deriving( Eq )

the deriving mechanism says "oh, we need Eq on each field, that is Eq a, Eq [a]". Then it simplifies that to arrive at the instance context.

For your example, it'd say "I need Data (f Bool), Data (f Int) and then get stuck. There are two ways to get unglued. One is simply to put those in the instance context

instance (Data (f Int), Data (f Bool)) => Data (Foo f) where ...

The other is to use quantified constraints. It's not clear which is best in general. And even figuring out the appropriate quantified-constraint generalisation of a set of ground constraints is far from trivial.

comment:2 Changed 22 months ago by RyanGlScott

I too am skeptical that there is a robust, systematic way to do what you're seeking. I think the intent of https://ghc.haskell.org/trac/ghc/ticket/12245#comment:1 was to combine quantified constraints with StandaloneDeriving, not have the quantified constraints be inferred.

comment:3 Changed 21 months ago by RyanGlScott

Resolution: wontfix
Status: newclosed

Closing, since this is neither how we want to tackle this problem, nor a solution that will work most of the time, as per comment:1.

comment:4 Changed 18 months ago by RyanGlScott

Keywords: wipT2893 removed
Note: See TracTickets for help on using tickets.