Opened 11 years ago

Closed 8 years ago

Last modified 7 years ago

#1769 closed task (fixed)

Deriving Typeable for data families

Reported by: chak Owned by: chak
Priority: low Milestone: 7.0.1
Component: Compiler (Type checker) Version: 6.9
Keywords: Cc: mmitar@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: indexed-types/should_compile/T1769
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


See Simon's proposal in the attachment.

Attachments (1)

DataFamilyDerivingTypable.txt (3.4 KB) - added by chak 11 years ago.

Download all attachments as: .zip

Change History (14)

Changed 11 years ago by chak


comment:1 Changed 10 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:2 Changed 10 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:4 Changed 8 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:5 Changed 8 years ago by igloo

Priority: normallow

comment:6 Changed 8 years ago by mitar

Cc: mmitar@… added
Type of failure: None/Unknown


This would be really great to have. Currently (7.0 from repository) it fails with:

    Can't make a derived instance of
      `Typeable (...)':
      `...' is a type family

But without Typeable I cannot make instance of Data for data types I have associated with my type class.

comment:7 Changed 8 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: indexed-types/should_compile/T1769

OK, I've done this

Mon Nov 15 23:11:46 GMT Standard Time 2010
  * Deriving Typeable changes
  * Fix a bug that led to a crash with
      data family T a
      deriving Functor T
  * Allow deriving Typeable for data families
      data family T a
      deriving Typeable1 T
  * Some refactoring and tidying

    M ./compiler/typecheck/TcDeriv.lhs -47 +58


comment:8 Changed 8 years ago by mitar

Will this be included in 7.0.2?

comment:9 Changed 8 years ago by simonpj

We don't add features in patch releases, just fix bugs. There is always pressure to put more features in as the deadline approaches, and we have to stop somewhere.

Still I suppose you could argue that this patch just fixes a bug. Adding it would break no programs. So I don't have a strong opinion. Ian, Simon, I defer to you.

comment:10 Changed 8 years ago by mitar

Without it my library cannot compile. This is why I am pushing for this.

comment:11 in reply to:  10 Changed 8 years ago by heatsink

Replying to mitar:

As a workaround, you can derive from Typeable without this feature by writing your own instance.

data family T a

instance Typeable a => Typeable (T a) where
  typeOf x = mkTyConApp (mkTyCon "T") [typeOf (unT x)]
      unT :: T a -> a
      unT = undefined

comment:12 Changed 8 years ago by mitar

This is really equal to what would deriving do?

comment:13 Changed 7 years ago by mitar

Wouldn't it be enough to define?

instance Typeable1 T where
  typeOf1 _ = mkTyConApp (mkTyCon "T") []
Note: See TracTickets for help on using tickets.