[GHC] #1830: Automatic derivation of Lift

GHC ghc-devs at haskell.org
Mon Aug 24 16:37:59 UTC 2015


#1830: Automatic derivation of Lift
-------------------------------------+-------------------------------------
        Reporter:  guest             |                   Owner:
                                     |  RyanGlScott
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:  ⊥
       Component:  Template Haskell  |                 Version:  6.8.1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:  Phab:D1168
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Replying to [comment:10 goldfire]:
 > What's wrong with using `th-lift`?

 Type inference. `th-lift` is fundamentally limited in that it cannot infer
 the correct instance context for complex data structures such as

 {{{#!hs
 data Nested f a = Nested (f a) deriving Lift

 -- instance Lift (f a) => Lift (Nested f a) where ...
 }}}

 or

 {{{#!hs
 data R a = R a

 instance (Show a, Lift a) => Lift (R a) where ...

 data Restricted a = Restricted (R a) deriving Lift

 -- instance (Show a, Lift a) => Lift (Restricted a) where ...
 }}}

 Granted, this could be improved if `th-lift` were changed to allow
 something like this:

 {{{#!hs
 instance (Show a, Lift a) => Lift (Restricted a) where
     lift = $(makeLift ''Restricted)
 }}}

 But a `deriving` statement is infinitely more aesthetically pleasing, in
 my opinion.

 > But that argument falls flat here, because users are clearly already
 using TH!

 Well, they're using the `template-haskell` library, but not necessarily
 the `TemplateHaskell` extension. Users may want to define `Lift` instances
 for data types without actually using the `TemplateHaskell` extension (as
 doing so precludes a library from being built on a stage-1 compiler).
 Having access to `DeriveLift` allows a library to be built with `Lift`
 support on GHC stage 1 and 2, and then downstream packages that depend on
 the library can decide if they want to actually utilize the `Lift`
 instances by means of the `TemplateHaskell` extension.

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


More information about the ghc-tickets mailing list