Opened 9 years ago

Closed 9 years ago

Last modified 2 years ago

#4530 closed bug (invalid)

Deriving Data for existentially quantified types

Reported by: mitar Owned by:
Priority: normal Milestone: 7.4.1
Component: Compiler Version: 7.1
Keywords: deriving Cc: mmitar@…
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

I cannot derive Data for:

data EqBox where
  EB :: forall e . (Data e, Eq e) => e -> EqBox

I am getting such error:

   Ambiguous type variable `e' in the constraints:
      (Eq e) arising from a use of `EB' at Test.hs:11:1-28
      (Data e) arising from a use of `k' at Test.hs:11:1-28
    Probable fix: add a type signature that fixes these type variable(s)
    In the first argument of `z', namely `EB'
    In the first argument of `k', namely `z EB'
    In the expression: k (z EB)
    When typechecking the code for  `gunfold'
      in a standalone derived instance for `Data EqBox':
      To see the code I am typechecking, use -ddump-deriv

Attachments (1)

Test.hs (241 bytes) - added by mitar 9 years ago.

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by mitar

Attachment: Test.hs added

comment:1 Changed 9 years ago by igloo

Milestone: 7.2.1

comment:2 Changed 9 years ago by simonpj

Resolution: invalid
Status: newclosed

Do you expect to be able to? If you use a 'deriving' clause on the data type decl you get this:

T4530.hs:8:22:
    Can't make a derived instance of `Data EqBox':
      Constructor `EB' does not have a Haskell-98 type
      Possible fix: use a standalone deriving declaration instead
    In the data type declaration for `EqBox'

With standalone deriving, GHC just generates the code and tries to typecheck it, and indeed fails. See the manual http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/deriving.html#stand-alone-deriving

What do you expect to happen? Can you write a Data instance by hand?

I think this behaviour is just what the manual says. If you disagree, re-open.

Simon

comment:3 in reply to:  2 Changed 9 years ago by mitar

Replying to simonpj:

What do you expect to happen? Can you write a Data instance by hand?

I do not know. I hopped that somebody else will know that. ;-)

comment:4 Changed 2 years ago by RyanGlScott

Keywords: deriving added
Note: See TracTickets for help on using tickets.