Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,259
    • Issues 5,259
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 565
    • Merge requests 565
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #5462
Closed
Open
Issue created Sep 05, 2011 by Simon Peyton Jones@simonpjDeveloper

Deriving clause for arbitrary classes

Currently, you can use a deriving clause, or standalone-deriving declaration, only for

  • a built-in class like Eq or Show, for which GHC knows how to generate the instance code
  • a newtype, via the "newtype-deriving" mechanism.

However, Pedros's new generic-default mechanism means that it makes perfect sense to write this:

data T a = ...blah..blah... deriving( Generic )

instance C a => C (T a)  -- No 'where' clause

where C is some random user-defined class. Usually, an instance decl with no 'where' clause would be pretty useless, but now that we have default method signatures, in conjunction with deriving( Generic ), the instance can be useful.

That in turn leads to a desire to say

data T a = ...blah..blah... deriving( Generic, C )

which is even more compact. Is the extra compactness worth it? Presumably we'd only want to do this for some specified classes C, so we'd need some way to say this at C's declaration site. Something like:

class C where
  op :: a -> a
  default op :: blah => a -> a
  op = <code for the default method>

{-# DERIVABLE C #-}   -- This says you can say
                      -- data T = ... deriving( C )

I'm a bit dubious about whether the payoff justifies the cost, but I'm recording the idea in this ticket.

Trac metadata
Trac field Value
Version 7.2.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC wadler@inf.ed.ac.uk
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking