Opened 6 years ago

Closed 15 months ago

#8263 closed feature request (wontfix)

allow duplicate deriving / standalone deriving

Reported by: aavogt Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.3
Keywords: deriving Cc:
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 would like to avoid conditional compilation. Currently I need to write:

#if MIN_VERSION_Cabal(1,18,0)
-- cabal 1.18 has these instances
#else
deriving instance Typeable Flag
#endif

Would it be sane to have the deriving instance do nothing if the imported instance that clashes was also derived?

reifyInstances together with a fixed #8100 could allow faking this feature.

Change History (5)

comment:1 Changed 6 years ago by simonpj

I'd rather not. It's another rule to implement and document in the manual.

Why not put deriving Typeable on the declaration of Flag?

Simon

comment:2 Changed 6 years ago by aavogt

Flag comes from cabal: that deriving (Typeable) was added in version 1.18. No code is needed to support that version. Things get messy to support older versions of Cabal which do not export a Typeable instance.

comment:3 Changed 3 years ago by RyanGlScott

I'm also inclined to reject this idea. Given the current richness of deriving language, it's possible to derive two instances which are almost the same but with subtle differences, e.g.,

deriving stock instance Show Bool
deriving newtype instance Show Bool

I imagine trying to detect duplicate instances would be a large headache.

comment:4 Changed 2 years ago by RyanGlScott

Keywords: deriving added

comment:5 in reply to:  3 Changed 15 months ago by monoidal

Resolution: wontfix
Status: newclosed

In the specific case of Typeable, since GHC 8.2 every data type is an instance of Typeable and we're ignoring "deriving instance Typeable" altogether.

In general case, there's the problem of deriving strategies from comment:3. We could, in principle, allow the declaration "deriving S instance T" if T was derived using the same strategy S elsewhere. However, this only solves the issue if the T was derived; if there's an "instance" declaration, I don't see any nice way to do it. So this feature would be rather limited in power; we don't have examples other than Typeable, and in the meantime #8100 was fixed.

I'm closing the ticket; please reopen if you still need this.

Note: See TracTickets for help on using tickets.