<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<h3>
Matthew Pickering pushed to branch wip/proposal-195
at <a href="https://gitlab.haskell.org/ghc/ghc">Glasgow Haskell Compiler / GHC</a>
</h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.haskell.org/ghc/ghc/-/commit/3db7cff992ec13f4cbeb355e3b623fd6c87949a8">3db7cff9</a></strong>
<div>
<span>by Matthew Pickering</span>
<i>at 2020-05-27T14:38:43+01:00</i>
</div>
<pre class="commit-message" style="white-space: pre-wrap; margin: 0;">Use a newtype `Code` for the return type of typed quotations (Proposal #195)
There are three problems with the current API:
1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition
of two type constructors. Doing so in your program involves making your own newtype and
doing a lot of wrapping/unwrapping.
For example, if I want to create a language which I can either run immediately or
generate code from I could write the following with the new API. ::
class Lang r where
_int :: Int -> r Int
_if :: r Bool -> r a -> r a -> r a
instance Lang Identity where
_int = Identity
_if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f)
instance Quote m => Lang (Code m) where
_int = liftTyped
_if cb ct cf = [|| if $$cb then $$ct else $$cf ||]
2. When doing code generation it is common to want to store code fragments in
a map. When doing typed code generation, these code fragments contain a
type index so it is desirable to store them in one of the parameterised
map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from
``parameterized-utils``.
::
compiler :: Env -> AST a -> Code Q a
data AST a where ...
data Ident a = ...
type Env = MapF Ident (Code Q)
newtype Code m a = Code (m (TExp a))
In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``.
Using one of these map types currently requires creating your own newtype and constantly
wrapping every quotation and unwrapping it when using a splice. Achievable, but
it creates even more syntactic noise than normal metaprogramming.
3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is
easier. This is a weak reason but one everyone
can surely agree with.
</pre>
</li>
</ul>
<h4>30 changed files:</h4>
<ul>
<li class="file-stats">
<a href="#06764eb0158306b83ab1998d18316392a51838c2">
compiler/GHC/Builtin/Names/TH.hs
</a>
</li>
<li class="file-stats">
<a href="#3aa56839e36b2219f9ad54f5646ef3005da9c672">
compiler/GHC/Tc/Deriv/Generate.hs
</a>
</li>
<li class="file-stats">
<a href="#9ea832ccdb4b5f7508a1efd6caedeafa16b269e7">
compiler/GHC/Tc/Gen/Splice.hs
</a>
</li>
<li class="file-stats">
<a href="#bdbe6161ac51a0072a62bb6ddfca5b31edfc51ff">
docs/users_guide/exts/deriving_extra.rst
</a>
</li>
<li class="file-stats">
<a href="#f0474104bf5123c0904d8fa7745d89840c730d16">
docs/users_guide/exts/template_haskell.rst
</a>
</li>
<li class="file-stats">
<a href="#b1ae9d61e7dc1aafaeeab37b56c3a045e926a855">
libraries/template-haskell/Language/Haskell/TH.hs
</a>
</li>
<li class="file-stats">
<a href="#dfa65b2523e009fd5494554a82e58536f442a6be">
<span class="new-file">
+
libraries/template-haskell/Language/Haskell/TH/CodeDo.hs
</span>
</a>
</li>
<li class="file-stats">
<a href="#556b3bb7c75dfe37155d079195cb9671e3061783">
libraries/template-haskell/Language/Haskell/TH/Lib.hs
</a>
</li>
<li class="file-stats">
<a href="#97b63f699307e7a6d92425265508cfc9e963c336">
libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
</a>
</li>
<li class="file-stats">
<a href="#ed3c6537b674490396f9cab5cbb014ee54e71168">
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
</a>
</li>
<li class="file-stats">
<a href="#ee61d093f9c845475278836990fdde8877a1de02">
libraries/template-haskell/changelog.md
</a>
</li>
<li class="file-stats">
<a href="#8f8341958f03c71e1eee3b82a943baee4c8d42f6">
libraries/template-haskell/template-haskell.cabal.in
</a>
</li>
<li class="file-stats">
<a href="#2d19e6cbace295d14f756857b7a73e885bca99f3">
libraries/text
</a>
</li>
<li class="file-stats">
<a href="#03f37b664b8d39fa3a162ae50b5010c251ebcebc">
testsuite/tests/deriving/should_compile/drv-empty-data.stderr
</a>
</li>
<li class="file-stats">
<a href="#d481260600d885b29b51ded399c9a6cfe2e35d5e">
testsuite/tests/parser/should_compile/Proposal229f_instances.hs
</a>
</li>
<li class="file-stats">
<a href="#cd05355aeb6f26bd996f6097b82cf76fd3dd5c22">
testsuite/tests/partial-sigs/should_compile/TypedSplice.hs
</a>
</li>
<li class="file-stats">
<a href="#e2dacf823e2e64f5ba90e1883b7d0727c48c5568">
testsuite/tests/partial-sigs/should_compile/TypedSplice.stderr
</a>
</li>
<li class="file-stats">
<a href="#714003f98c966f2f558b07ec612e6fb8d3ee38bb">
testsuite/tests/quotes/T17857.hs
</a>
</li>
<li class="file-stats">
<a href="#b50e1d9fe31070c946ce875e81fc7fc970636410">
testsuite/tests/th/T10945.stderr
</a>
</li>
<li class="file-stats">
<a href="#cbc2decac883eb747be641225d72369cbffd33ea">
testsuite/tests/th/T15471A.hs
</a>
</li>
<li class="file-stats">
<a href="#721ab42ecc9d63f9c0401a02fcd2fd41b4746ce9">
testsuite/tests/th/T15843.hs
</a>
</li>
<li class="file-stats">
<a href="#30f5fd56b0d0ab0e926cb14b83cb4e81955cb786">
testsuite/tests/th/T16195A.hs
</a>
</li>
<li class="file-stats">
<a href="#a9e71d5ec5a1ec7dbf17d99f2df2caeeb0f30eb8">
testsuite/tests/th/T18121.hs
</a>
</li>
<li class="file-stats">
<a href="#5c93e183dd50843ee7e5d40645a86fd417ef7729">
testsuite/tests/th/T8577.stderr
</a>
</li>
<li class="file-stats">
<a href="#759357c210b1802b1d976d55b82fb27b2bf87d22">
testsuite/tests/th/T8577a.hs
</a>
</li>
<li class="file-stats">
<a href="#a8ddd2863882bf581aa5a0b5f7659d8e6465bd7a">
testsuite/tests/th/TH_StringLift.hs
</a>
</li>
<li class="file-stats">
<a href="#c3f2d4372592161448b8a605b988da55c7d7c1cb">
testsuite/tests/th/TH_reifyLocalDefs.hs
</a>
</li>
<li class="file-stats">
<a href="#45cceda25d894a5e1f71795af62ef092461aaf66">
testsuite/tests/th/overloaded/T17839.hs
</a>
</li>
<li class="file-stats">
<a href="#1d24574fb0932b3af57d11a7d3987a34ae6a6604">
testsuite/tests/th/overloaded/TH_overloaded_constraints.hs
</a>
</li>
<li class="file-stats">
<a href="#2c494b7ea00b167f244dd2181850155716a0ee73">
testsuite/tests/th/overloaded/TH_overloaded_csp.hs
</a>
</li>
</ul>
<h5>The diff was not included because it is too large.</h5>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #777;">
—
<br>
<a href="https://gitlab.haskell.org/ghc/ghc/-/commit/3db7cff992ec13f4cbeb355e3b623fd6c87949a8">View it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.haskell.org.
If you'd like to receive fewer emails, you can
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://gitlab.haskell.org/ghc/ghc/-/commit/3db7cff992ec13f4cbeb355e3b623fd6c87949a8"}}</script>
</p>
</div>
</body>
</html>