Ticket #4529 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

Deriving Data does not work for attached code

Reported by: mitar Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.1
Keywords: Cc: mmitar@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

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

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

Change History

Changed 2 years ago by mitar

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

Changed 2 years ago by mitar

Correct file for this ticket

Changed 2 years ago by mitar

Changed 2 years ago by mitar

I also overwrote first attachment with correct version.

Changed 2 years ago by simonpj

  • status changed from new to closed
  • resolution set to invalid

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

Note: See TracTickets for help on using tickets.