summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2019-04-17 08:07:52 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-04-18 22:52:25 -0400
commit57cf113302eee6068a1b10cba348f4b7de7faeae (patch)
tree3542f990a72d4f3f8bbdd8965e6b2a82d5ea9d75 /docs
parent5988f17a799ba3416bb6ed539ae65e1f3fd9f2c0 (diff)
downloadhaskell-57cf113302eee6068a1b10cba348f4b7de7faeae.tar.gz
TH: make `Lift` and `TExp` levity-polymorphic
Besides the obvious benefits of being able to manipulate `TExp`'s of unboxed types, this also simplified `-XDeriveLift` all while making it more capable. * `ghc-prim` is explicitly depended upon by `template-haskell` * The following TH things are parametrized over `RuntimeRep`: - `TExp(..)` - `unTypeQ` - `unsafeTExpCoerce` - `Lift(..)` * The following instances have been added to `Lift`: - `Int#`, `Word#`, `Float#`, `Double#`, `Char#`, `Addr#` - unboxed tuples of lifted types up to arity 7 - unboxed sums of lifted types up to arity 7 Ideally we would have levity-polymorphic _instances_ of unboxed tuples and sums. * The code generated by `-XDeriveLift` uses expression quotes instead of generating large amounts of TH code and having special hard-coded cases for some unboxed types.
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/8.10.1-notes.rst6
-rw-r--r--docs/users_guide/glasgow_exts.rst32
2 files changed, 18 insertions, 20 deletions
diff --git a/docs/users_guide/8.10.1-notes.rst b/docs/users_guide/8.10.1-notes.rst
index 21a7f2b275..1c47a002d7 100644
--- a/docs/users_guide/8.10.1-notes.rst
+++ b/docs/users_guide/8.10.1-notes.rst
@@ -73,6 +73,12 @@ Runtime system
Template Haskell
~~~~~~~~~~~~~~~~
+- The ``Lift`` typeclass is now levity-polymorphic and has a ``liftTyped``
+ method. Previously disallowed instances for unboxed tuples, unboxed sums, an
+ primitive unboxed types have also been added. Finally, the code generated by
+ :ghc-flags:`-XDeriveLift` has been simplified to take advantage of expression
+ quotations.
+
``ghc-prim`` library
~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index 1c1d4cbb85..781a10691e 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -4531,7 +4531,8 @@ Deriving ``Lift`` instances
The class ``Lift``, unlike other derivable classes, lives in
``template-haskell`` instead of ``base``. Having a data type be an instance of
``Lift`` permits its values to be promoted to Template Haskell expressions (of
-type ``ExpQ``), which can then be spliced into Haskell source code.
+type ``ExpQ`` and ``TExpQ a``), which can then be spliced into Haskell source
+code.
Here is an example of how one can derive ``Lift``:
@@ -4546,17 +4547,11 @@ Here is an example of how one can derive ``Lift``:
{-
instance (Lift a) => Lift (Foo a) where
- lift (Foo a)
- = appE
- (conE
- (mkNameG_d "package-name" "Bar" "Foo"))
- (lift a)
- lift (u :^: v)
- = infixApp
- (lift u)
- (conE
- (mkNameG_d "package-name" "Bar" ":^:"))
- (lift v)
+ lift (Foo a) = [| Foo a |]
+ lift ((:^:) u v) = [| (:^:) u v |]
+
+ liftTyped (Foo a) = [|| Foo a ||]
+ liftTyped ((:^:) u v) = [|| (:^:) u v ||]
-}
-----
@@ -4572,8 +4567,9 @@ Here is an example of how one can derive ``Lift``:
fooExp :: Lift a => Foo a -> Q Exp
fooExp f = [| f |]
-:extension:`DeriveLift` also works for certain unboxed types (``Addr#``, ``Char#``,
-``Double#``, ``Float#``, ``Int#``, and ``Word#``):
+Note that the ``Lift`` typeclass takes advantage of :ref:`runtime-rep` in order
+to support instances involving unboxed types. This means :extension:`DeriveLift`
+also works for these types:
::
@@ -4587,12 +4583,8 @@ Here is an example of how one can derive ``Lift``:
{-
instance Lift IntHash where
- lift (IntHash i)
- = appE
- (conE
- (mkNameG_d "package-name" "Unboxed" "IntHash"))
- (litE
- (intPrimL (toInteger (I# i))))
+ lift (IntHash i) = [| IntHash i |]
+ liftTyped (IntHash i) = [|| IntHash i ||]
-}