<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.Code, li.Code, div.Code
{mso-style-name:Code;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:9.0pt;
font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.m-4256948752900361843code, li.m-4256948752900361843code, div.m-4256948752900361843code
{mso-style-name:m_-4256948752900361843code;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.m-4256948752900361843msolistparagraph, li.m-4256948752900361843msolistparagraph, div.m-4256948752900361843msolistparagraph
{mso-style-name:m_-4256948752900361843msolistparagraph;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.m-4256948752900361843msoplaintext, li.m-4256948752900361843msoplaintext, div.m-4256948752900361843msoplaintext
{mso-style-name:m_-4256948752900361843msoplaintext;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
.MsoPapDefault
{mso-style-type:export-only;
margin-top:6.0pt;
margin-right:0cm;
margin-bottom:6.0pt;
margin-left:0cm;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">David says that this paper is relevant<o:p></o:p></span></p>
<p class="MsoNormal"><a href="http://okmij.org/ftp/Haskell/tr-15-04.pdf" target="_blank">http://okmij.org/ftp/Haskell/tr-15-04.pdf</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Simon<span style="font-family:"Calibri",sans-serif"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> David Feuer [mailto:david.feuer@gmail.com]
<br>
<b>Sent:</b> 14 January 2017 00:50<br>
<b>To:</b> Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Cc:</b> ghc-devs <ghc-devs@haskell.org>; Edward Kmett <ekmett@gmail.com><br>
<b>Subject:</b> RE: Magical function to support reflection<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I need to look through a bit more of this, but explicit type application certainly can be avoided using Tagged. Once we get the necessary magic, libraries will be able to come up with whatever interfaces they like. My main concern about the generality of<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">reify# :: forall r. (RC a => r) -> a -> r</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">(as with the primop type Edward came up with) is that it lacks the `forall s` safety mechanism of the reflection library. Along with its key role in ensuring class coherence[*], that mechanism also makes it clear
what specialization is and is not allowed to do with reified values. Again, I'm not sure it can mess up the simpler/more general form you and Edward propose, but it makes me nervous.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">[*] Coherence: as long as an instance of Reifies S A exists for some concrete S::K, users can't incoherently write a polymorphic Reifies instance for s::K.</span><o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
On Jan 13, 2017 7:33 PM, "Simon Peyton Jones" <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">David, Edward</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Here’s my take on this thread about reflection. I’ll ignore Tagged and the ‘s’ parameter, and the proxy arguments, since they are
incidental.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">I can finally see a reasonable path; I think there’s a potential GHC proposal here.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Simon</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">First thing</span></b><span style="font-family:"Calibri",sans-serif">: PLEASE let's give a Core rendering of whatever is proposed.
If it's expressible in Core that's reassuring. If it requires an extension to Core, that's a whole different thing.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">Second</span></b><span style="font-family:"Calibri",sans-serif">. For any
<i>particular</i> class, I think it's easy to express reify in Core. Example (in Core):</span><o:p></o:p></p>
<p class="m-4256948752900361843code">reifyTypeable :: (Typeable a => b) -> TypeRep a -> b<o:p></o:p></p>
<p class="m-4256948752900361843code">reifyTypable k = k |> co<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">where co is a coercion that witnesses</span><o:p></o:p></p>
<p class="m-4256948752900361843code"> co :: (forall a b. Typeable a => b) ~ forall a b. (TypeRep a -> b)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif"> </span></b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">Third.
</span></b><span style="font-family:"Calibri",sans-serif">This does not depend, and should not depend, on the fact that single-method classes are represented with a newtype. E.g. if we changed Typeable to be represented with a data type thus (in Core)</span><o:p></o:p></p>
<p class="m-4256948752900361843code">data Typeable a = MkTypeable (TypeRep a)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">using data rather than newtype, then we could still write reifyTypable.</span><o:p></o:p></p>
<p class="m-4256948752900361843code">reifyTypeable :: (Typeable a => b) -> TypeRep a -> b<o:p></o:p></p>
<p class="m-4256948752900361843code">reifyTypable = /\ab. \(f :: Typeable a => b). \(r :: TypeRep a).<o:p></o:p></p>
<p class="m-4256948752900361843code"> f (MkTypeable r)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">The efficiency of newtype is nice, but it’s not essential.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif"> </span></b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">Fourth</span></b><span style="font-family:"Calibri",sans-serif">. As you point out, reify# is far too polymorphic.
<b>Clearly you need reify# to be a class method!</b> Something like this</span><o:p></o:p></p>
<p class="m-4256948752900361843code">class Reifiable a where<o:p></o:p></p>
<p class="m-4256948752900361843code"> type RC a :: Constraint -- Short for Reified Constraint<o:p></o:p></p>
<p class="m-4256948752900361843code"> reify# :: forall r. (RC a => r) -> a -> r<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Now (in Core at least) we can make instances</span><o:p></o:p></p>
<p class="m-4256948752900361843code">instance Reifiable (TypeRep a) where<o:p></o:p></p>
<p class="m-4256948752900361843code"> type RC (TypeRep a) = Typeable a<o:p></o:p></p>
<p class="m-4256948752900361843code"> reify# k = k |> co -- For a suitable co<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Now, we can’t write those instances in Haskell, but we could make the ‘deriving’ mechanism deal with it, thus:</span><o:p></o:p></p>
<p class="m-4256948752900361843code">deriving instance Reifiable (Typeable a)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">You can supply a ‘where’ part if you like, but if you don’t GHC will fill in the implementation for you. It’ll check that Typeable
is a single-method class; produce a suitable implementation (in Core, as above) for reify#, and a suitable instance for RC. Pretty simple. Now the solver can use those instances.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">There are lots of details</span><o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-family:"Calibri",sans-serif">I’ve used a single parameter class and a type function, because the call site of reify# will provide no information about the ‘c’ in (c => r) argument.</span><o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-family:"Calibri",sans-serif">What if some other class has the same method type? E.g. if someone wrote
</span><o:p></o:p></p>
<p class="m-4256948752900361843code">class MyTR a where op :: TypeRep a<o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:"Calibri",sans-serif">would that mess up the use of reify# for Typeable? Well it would if they also did</span><o:p></o:p></p>
<p class="m-4256948752900361843code">deriving instance Reifiable (MyTR a)<o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:"Calibri",sans-serif">And there really is an ambiguity: what should (reify# k (tr :: TypeRep Int)) do? Apply k to a TypeRep or to a MyTR? So a complaint here would be entirely legitimate.</span><o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-family:"Calibri",sans-serif">I suppose that another formulation might be to abstract over the constraint, rather than the method type, and use explicit type application at calls of reify#. So</span><o:p></o:p></p>
<p class="m-4256948752900361843code">class Reifiable c where<o:p></o:p></p>
<p class="m-4256948752900361843code"> type RL c :: *<o:p></o:p></p>
<p class="m-4256948752900361843code"> reify# :: (c => r) -> RL c -> r<o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:"Calibri",sans-serif">Now all calls of reify# would have to look like
</span><o:p></o:p></p>
<p class="m-4256948752900361843code">reify# @(Typeable Int) k tr<o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:"Calibri",sans-serif">Maybe that’s acceptable. But it doesn’t seem as nice to me.</span><o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-family:"Calibri",sans-serif">One could use functional dependencies and a 2-parameter type class, but I don’t think it would change anything much. If type functions work, they are more robust than fundeps.</span><o:p></o:p></p>
<p class="m-4256948752900361843msolistparagraph"><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-family:"Calibri",sans-serif">One could abstract over the type constructor rather than the type. I see no advantage and some disadvantages</span><o:p></o:p></p>
<p class="m-4256948752900361843code">class Reifiable t where<o:p></o:p></p>
<p class="m-4256948752900361843code"> type RC t :: * -> Constraint -- Short for Reified Constraint<o:p></o:p></p>
<p class="m-4256948752900361843code"> reify# :: forall r. (RC t a => r) -> t a -> r<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">-----Original Message-----</span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">From: ghc-devs [<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">mailto:ghc-devs-bounces@haskell.org</a>] On Behalf Of David</span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">Feuer</span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">Sent: 11 December 2016 05:01</span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">To: ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>>; Edward Kmett <<a href="mailto:ekmett@gmail.com" target="_blank">ekmett@gmail.com</a>></span><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <span lang="EN-US">Subject: Magical function to support reflection</span><o:p></o:p></p>
<div>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| The following proposal (with fancier formatting and some improved<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| wording) can be viewed at<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <a href="https://ghc.haskell.org/trac/ghc/wiki/MagicalReflectionSupport" target="_blank">
<span style="color:windowtext;text-decoration:none">https://ghc.haskell.org/trac/ghc/wiki/MagicalReflectionSupport</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| Using the Data.Reflection has some runtime costs. Notably, there can be no<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| inlining or unboxing of reified values. I think it would be nice to add a<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| GHC special to support it. I'll get right to the point of what I want, and<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| then give a bit of background about why.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| === What I want<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| I propose the following absurdly over-general lie:<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify# :: (forall s . c s a => t s r) -> a -> r<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| `c` is assumed to be a single-method class with no superclasses whose<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| dictionary representation is exactly the same as the representation of `a`,<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| and `t s r` is assumed to be a newtype wrapper around `r`. In desugaring,<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify# f would be compiled to f@S, where S is a fresh type. I believe it's<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| necessary to use a fresh type to prevent specialization from mixing up<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| different reified values.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| === Background<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| Let me set up a few pieces. These pieces are slightly modified from what the<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| package actually does to make things cleaner under the hood, but the<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| differences are fairly shallow.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| newtype Tagged s a = Tagged { unTagged :: a }<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| unproxy :: (Proxy s -> a) -> Tagged s a<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| unproxy f = Tagged (f Proxy)<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| class Reifies s a | s -> a where<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reflect' :: Tagged s a<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| -- For convenience<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reflect :: forall s a proxy . Reifies s a => proxy s -> a reflect _ =<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| unTagged (reflect' :: Tagged s a)<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| -- The key function--see below regarding implementation reify' :: (forall s<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| . Reifies s a => Tagged s r) -> a -> r<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| -- For convenience<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify :: a -> (forall s . Reifies s a => Proxy s -> r) -> r reify a f =<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify' (unproxy f) a<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| The key idea of reify' is that something of type<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| forall s . Reifies s a => Tagged s r<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| is represented in memory exactly the same as a function of type<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| a -> r<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| So we can currently use unsafeCoerce to interpret one as the other.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| Following the general approach of the library, we can do this as such:<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| newtype Magic a r = Magic (forall s . Reifies s a => Tagged s r) reify' ::<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| (forall s . Reifies s a => Tagged s r) -> a -> r reify' f = unsafeCoerce<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| (Magic f)<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| This certainly works. The trouble is that any knowledge about what is<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reflected is totally lost. For instance, if I write<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify 12 $ \p -> reflect p + 3<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| then GHC will not see, at compile time, that the result is 15. If I write<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| reify (+1) $ \p -> reflect p x<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| then GHC will never inline the application of (+1). Etc.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| I'd like to replace reify' with reify# to avoid this problem.<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| Thanks,<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| David Feuer<o:p></o:p></p>
</div>
<p class="m-4256948752900361843msoplaintext">| _______________________________________________<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| ghc-devs mailing list<o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <a href="mailto:ghc-devs@haskell.org" target="_blank">
<span style="color:windowtext;text-decoration:none">ghc-devs@haskell.org</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext">| <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c47a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quvCny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0" target="_blank">
<span style="color:windowtext;text-decoration:none">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext"><a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c47a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quvCny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0" target="_blank"><span style="color:windowtext;text-decoration:none">|
.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext"><a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c47a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quvCny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0" target="_blank"><span style="color:windowtext;text-decoration:none">|
devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c4</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext"><a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c47a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quvCny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0" target="_blank"><span style="color:windowtext;text-decoration:none">|
7a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quv</span></a><o:p></o:p></p>
<p class="m-4256948752900361843msoplaintext"><a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%7Csimonpj%40microsoft.com%7C488bf00986e34ac0833208d42182c47a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636170292905032831&sdata=quvCny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0" target="_blank"><span style="color:windowtext;text-decoration:none">|
Cny8vD%2Fw%2BjIIypEtungW3OWbVmCQxFAK4%2FXrX%2Bb8%3D&reserved=0</span></a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>