[GHC] #8503: New GeneralizedNewtypeDeriving check still isn't permissive enough

GHC ghc-devs at haskell.org
Tue Nov 5 22:27:48 UTC 2013


#8503: New GeneralizedNewtypeDeriving check still isn't permissive enough
-------------------------------------+------------------------------------
        Reporter:  goldfire          |            Owner:  goldfire
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  Compiler          |          Version:  7.7
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by simonpj):

 Cool idea. I like it.

 For the most part, the 'deriving' mechanism generates an instance decl in
 `HsSyn RdrName` and feeds it through the renamer and type checker.  We
 could do that for deriving decls too, like this:
 {{{
 newtype Age = MkAge Int deriving( C )
 }}}
 would generate
 {{{
 instance C Int => C Age where
   meth = coerce (meth :: Int -> F Int)
 }}}
 Here we simply call `coerce`, which wakes up the `Coercible` stuff.  It's
 a bit of a nuisance that we have to specify a type signature (in `HsType`)
 for `meth`, so that the from-type of the `coerce` is known, but not too
 bad.

 What you say about inferring `Coercible` constraints also makes sense.

 This would have another benefit: making GND much more uniform with the
 other instances.  See `TcEnv.InstInfo`. We can probably get rid of
 `NewTypeDerived` altogether, by generating a `VanillaInst` instead!

 Simon

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


More information about the ghc-tickets mailing list