[GHC] #8165: Use GeneralizedNewtypeDeriving to automatically create associated type families

GHC ghc-devs at haskell.org
Tue Oct 25 07:34:25 UTC 2016


#8165: Use GeneralizedNewtypeDeriving to automatically create associated type
families
-------------------------------------+-------------------------------------
        Reporter:  MikeIzbicki       |                Owner:  goldfire
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.1
       Component:  Compiler (Type    |              Version:  7.6.3
  checker)                           |
      Resolution:                    |             Keywords:  TypeFamilies
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #2721             |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 The recipe gave in comment:4 doesn't work for the example in comment:14.
 I could elaborate the recipe a bit thus:
 {{{
 class C x y z where
   type T y z x
   op :: x -> [y] -> z

 newtype N a = MkN <rep-type> deriving( C )

 -- Here the deriving clause would generate

 instance C x y <rep-type> => C x y (N a) where
   type T y (N a) x = T y <rep-type> x
   op = coerce (op :: x -> [y] -> <rep-type>)
 }}}
 The recipe for generating the `type instance` is to replace the occurrence
 of `z` (which must occur) with `<rep-type>` on the LHS and RHS.  I don't
 think it need be the last parameter of `T`, as the example shows.

 I'm far from sure if this is really worth the effort of explaining and
 implementing it.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8165#comment:18>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list