Proposal: Automatic derivation of Lift
tomberek at gmail.com
Mon Sep 7 18:36:22 UTC 2015
Yes, I would find DeriveLift useful and a pleasant improvement to the
Template Haskell ecosystem.
I am relatively new to TH and was wondering about a few things (if this
hijacks the thread we can start a new one);
Other quotations, [m| for 'Q Match' would be helpful to define collections
of matches that can be combined and manipulated. One can use Q
(Pat,Body,[Decl]) but you lose the ability for the Body to refer to a
variable bound in the Pat. One can use Q Exp for just a Lambda, but you
cant just combine lambdas to create a Match expression without some
Promotion of a Pat to an Exp. A subset of Pat can create an expression such
that \ $pat -> $(promote pat) is id.
There is a Lift typeclass defined in template-haskell  which, when
a data type is an instance, permits it to be directly used in a TH
quotation, like so
data Example = Example
instance Lift Example where
lift Example = conE (mkNameG_d "<package-name>" "<module-name>"
e :: Example
e = [| Example |]
Making Lift instances for most data types is straightforward and
mechanical, so the proposal is to allow automatic derivation of Lift
via a -XDeriveLift extension:
data Example = Example deriving Lift
This is actually a pretty a pretty old proposal , dating back to
2007. I wanted to have this feature for my needs, so I submitted a
proof-of-concept at the GHC Trac issue page .
The question now is: do we really want to bake this feature into GHC?
Since not many people opined on the Trac page, I wanted to submit this
here for wider visibility and to have a discussion.
Here are some arguments I have heard against this feature (please tell
me if I am misrepresenting your opinion):
* We already have a th-lift package  on Hackage which allows
derivation of Lift via Template Haskell functions. In addition, if
you're using Lift, chances are you're also using the -XTemplateHaskell
extension in the first place, so th-lift should be suitable.
* The same functionality could be added via GHC generics (as of GHC
7.12/8.0, which adds the ability to reify a datatype's package name
), if -XTemplateHaskell can't be used.
* Adding another -XDerive- extension places a burden on GHC devs to
maintain it in the future in response to further Template Haskell
Here are my (opinionated) responses to each of these:
* th-lift isn't as fully-featured as a -XDerive- extension at the
moment, since it can't do sophisticated type inference  or derive
for data families. This is something that could be addressed with a
patch to th-lift, though.
* GHC generics wouldn't be enough to handle unlifted types like Int#,
Char#, or Double# (which other -XDerive- extensions do).
* This is a subjective measurement, but in terms of the amount of code
I had to add, -XDeriveLift was substantially simpler than other
-XDerive extensions, because there are fewer weird corner cases. Plus,
I'd volunteer to maintain it :)
Simon PJ wanted to know if other Template Haskell programmers would
find -XDeriveLift useful. Would you be able to use it? Would you like
to see a solution other than putting it into GHC? I'd love to hear
feedback so we can bring some closure to this 8-year-old feature
ghc-devs mailing list
ghc-devs at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ghc-devs