<div dir="ltr"><div><div>Hi Simon,<br><br>Here's some context on what I'm after. I'll try to include enough to clarify what I'm after, without dragging you into unnecessary detail.<br><br>I have a Core expression, which I'm systematically translating to a related Core expression. The second one reifies the first one, so that the generated code *evaluates* to a run-time (not compile/Core-time) representation akin to the original Core expression. In this second (reified) representation, I need some run-time representation of types. I use Typeable constraints in my representation, and these constraints don't appear in the original Core representation. For instance, I have the following constructor for function application in a GADT of lambda expressions:<br>

<br>> (:^) :: (Typeable a, Typeable b) => E (a -> b) -> E a -> E b<br><br>My reification plugin takes a Core application expression, recursively reifies the function and argument expressions, and makes an expression that applies (:^) to the two recursive results. However--and the point of this thread--I also need to come up with Core expressions for the two Typeable dictionaries.<br>

<br>So, to clarify my request, given a Core type representation t, I want to construct a Core expression that evaluates to the dictionary for Typeable t if one exists, or fail if there isn't one. Note that t is not necessarily an atomic type; it could instead be something like [(Bool,Int -> String)].<br>

<br></div>I'm happy to Skype-chat if it'd help.<br><br></div>Thanks,  - Conal<br><div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 5, 2013 at 2:37 PM, Simon Peyton-Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link="blue" vlink="purple" lang="EN-GB">
<div><div class="im">
<p style="margin-left:36.0pt">We just don't know how to start — ie how call the right functions from the type checker. Are there any resources explaining the relevant subset of the TcRnIf API?<u></u><u></u></p>
</div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">And I for my part don’t know where to start helping you!  Conal wrote<u></u><u></u></span></p>

<div class="im">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt">I don't think I need to construct dictionaries for new Typeable instances. I only need to find and assemble *existing* Typeable instances into combinations like Typeable [(Bool,Int -> String)], and I don't know
 how to do so in a GHC plug-in<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">That’s exactly what the constraint solver does.  (TcSimplify and friends.)  But again I need more context.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">I gather you are talking to Pedro too?  He knows a lot about this stuff.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">Also there are a bunch of folk (Luite, Edsko) worked on the new front-end plugin stuff, and are much more expert in it than me.<u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">We could have a skype call if that would help<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d">S<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Verdana","sans-serif";color:#1f497d"><u></u> <u></u></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 style="font-size:11.0pt;font-family:"Calibri","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" lang="EN-US"> Nicolas Frisby [mailto:<a href="mailto:nicolas.frisby@gmail.com" target="_blank">nicolas.frisby@gmail.com</a>]
<br>
<b>Sent:</b> 05 November 2013 14:36<br>
<b>To:</b> Simon Peyton-Jones<br>
<b>Cc:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>; Conal Elliott<br>
<b>Subject:</b> RE: Finding & assembling class dictionaries from GHC plugins?<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p>On Nov 5, 2013 3:14 AM, "Simon Peyton-Jones" <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<u></u><u></u></p>
<p>><br>
> A core-level plug-in can’t generate fresh instances.  There are some new plug-in hooks that fit earlier in the pipeline, which can.  Maybe you can use that, and generate a data type decl with “deriving Typeable”?<u></u><u></u></p>


<p>We're willing to do some awkward shoehorning in HERMIT to make this work in limited circumstances. (Hopefully including Conal's.)<u></u><u></u></p>
<p>We just don't know how to start — ie how call the right functions from the type checker. Are there any resources explaining the relevant subset of the TcRnIf API?<u></u><u></u></p>
<p>Thanks.<u></u><u></u></p>
<p>>  <br>
><br>
> From: ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>] On Behalf Of Conal Elliott<br>
> Sent: 04 November 2013 20:08<br>
> To: <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> Subject: Finding & assembling class dictionaries from GHC plugins?<br>
><br>
>  <br>
><br>
> I'm working on a GHC plugin (for compiling Haskell to hardware), and I need to synthesize Typeable (and maybe other) class dictionaries for a wide range of types, including composite types (functions, pairs, lists, etc). Can it be done, and how? I think I'm
 mainly looking for mechanics of finding existing class instances (however they're defined) and assembling them (for parametrized/composite dictionaries), rather than mechanisms specific to Typeable.<br>
><br>
> Thanks, -- Conal<br>
><br>
><br>
> _______________________________________________<br>
> ghc-devs mailing list<br>
> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
><u></u><u></u></p>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>