Opened 10 years ago

Last modified 8 months ago

#3205 new feature request

Generalized isomorphic deriving

Reported by: ajd Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.2
Keywords: language, deriving Cc: Iceland_jack
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


A newtype is isomorphic to the type that it is based on. For example, newtype A = A Int is isomorphic to Int, so it is possible to automatically derive all of Int's instance for A.

It would be nice if this could be extended to other datatypes that were isomorphic to each other. For example, this would work

data K a = K a a a

instance C (K a) where

data L a = L a a a
  deriving (Eq,C<-K,Show)

where the C<-K notation means "derive an instance of C for this type that is 'the same as' the instance of C for K". The compiler would have to check that K and L were actually isomorphic.

I don't know if this is possible with the current internals of GHC, but it would be cool if it would be done. My main usage scenario would be deriving things for single-argument data constructors based on tuples; for example for serialization classes.

Change History (5)

comment:1 Changed 10 years ago by igloo

difficulty: Unknown
Milestone: _|_

Thanks for the suggestion.

comment:2 Changed 5 years ago by thomie

Keywords: language added
Type of failure: None/Unknown

comment:3 Changed 2 years ago by Iceland_jack

Cc: Iceland_jack added

comment:4 Changed 2 years ago by RyanGlScott

Keywords: deriving added

comment:5 Changed 8 months ago by harpocrates

Isn't this feature request now implemented as DerivingVia? Perhaps we could close this ticket?

Note: See TracTickets for help on using tickets.