Skip to content

GeneralizedNewtypeDeriving + TypeFamilies doesn't work

It would be nice if we could do stuff like this:

{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies, FlexibleContexts, FlexibleInstances #-}
class K a where
  bar :: a -> a

class K (B a) => M a where
  data B a :: *
  foo :: B a -> B a

instance M Bool where
  data B Bool = B1Bool Bool | B2Bool Bool
  foo = id

instance K (B Bool) where
  bar = id

instance M Int where
  newtype B Int = BInt (B Bool) deriving K
  foo = id

which currently gives the error

foo.hs:17:41:
    Can't make a derived instance of `K (B Int)'
      (even with cunning newtype deriving:
       the newtype may be recursive)
    In the newtype instance declaration for `B'

However, the newtype is not recursive, it is just an associated datatype from another class, so it seems like this ought to work.

Trac metadata
Trac field Value
Version 6.10.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information