Opened 9 years ago

Closed 9 years ago

Last modified 2 years ago

#4529 closed bug (invalid)

Deriving Data does not work for attached code

Reported by: mitar Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) 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

For attached code I get this error:

Test2.hs:19:48:
    Could not deduce (Real r, Random r)
      from the context (Data r, Typeable1 t)
      arising from a use of `f'
    Possible fix:
      add (Real r, Random r) to the context of
        the type signature for `dataCast1'
        or the instance declaration
    In the first argument of `gcast1', namely `f'
    In the expression: gcast1 f
    In an equation for `dataCast1': dataCast1 f = gcast1 f

Attachments (2)

Test2.2.hs (493 bytes) - added by mitar 9 years ago.
Correct file for this ticket
Test2.hs (493 bytes) - added by mitar 9 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 9 years ago by mitar

Ups, I attached wrong test code. Please delete that one. I am attaching correct file now.

Changed 9 years ago by mitar

Attachment: Test2.2.hs added

Correct file for this ticket

Changed 9 years ago by mitar

Attachment: Test2.hs added

comment:2 Changed 9 years ago by mitar

I also overwrote first attachment with correct version.

comment:3 Changed 9 years ago by simonpj

Resolution: invalid
Status: newclosed

You have

data (Real r, Show r, Random r, Data r)
  => RandomFoo r = RandomFoo (RandomBar r) 
  deriving (Typeable, Data)

As you'll see if you say -ddump-deriv (I'm improving the layout) you get a Data instance with (Real r, Random r) in the context? Why? Because the instance pattern matches on the constructor.

Solution: simply remove the context from the data declaration, giving

data RandomFoo r = RandomFoo (RandomBar r) 
  deriving (Typeable, Data)

The context (which is a Haskell mis-feature) does you no good, and as you have seen, it does you harm.

Simon

comment:4 Changed 2 years ago by RyanGlScott

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