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,407
    • Issues 5,407
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 599
    • Merge requests 599
  • 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
  • #2721
Closed
Open
Issue created Oct 22, 2008 by rl@cse.unsw.edu.au@trac-rl

Newtype deriving doesn't work with type families

This assumes -XTypeFamiles -XGeneralizedNewtypeDeriving. Example:

class C a where
  type T a
  foo :: a -> T a

instance C Int where
  type T Int = Int
  foo = id

newtype N = N Int deriving(C)

This happily produces an instance C N but no type instance T N. It should either (preferably) generate

type instance T N = Int

or fail. The example also compiles if T is a data family (the Int instance needs to be change accordingly). It should probably fail in this case.

BTW, this also compiles fine, with rather dramatic consequences:

type family T a
class C a where
  foo :: a -> T a

type instance T Int = Int
instance C Int where
  foo = id

type instance T N = Double
newtype N = N Int deriving(C)

I guess this last example is the same bug as #1496 (closed). I wonder if the deriving clause could generate something like:

instance T Int ~ T N => C Int
Edited Mar 09, 2019 by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking