Hi Michael, I was able to do what I wanted using reify instead of reifyInstances, and also I used applyT instead of substT.<div><br></div><div>Thanks<br><br><div class="gmail_quote">2012/4/13 Ismael Figueroa Palet <span dir="ltr">&lt;<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for your reply, in particular the reference to subsT!<div>I will work more on this next monday, and report my progress</div>
<div><br></div><div>Cheers!<br><div><div><div class="h5"><br><br>
<div class="gmail_quote">2012/4/13 Michael Sloan <span dir="ltr">&lt;<a href="mailto:mgsloan@gmail.com" target="_blank">mgsloan@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hello!<br>
<br>
It seems like you would want to use &quot;reifyInstances&quot; in order to get<br>
all of the instances associated with a class.  Then, you can match up<br>
the variables in each instance with the variables in the class<br>
declaration, and create a mapping from the class variables to the<br>
instance parameters.  Then, you can apply these mappings with substT:<br>
<a href="http://hackage.haskell.org/packages/archive/haskell-src-meta/0.5.1.2/doc/html/Language-Haskell-Meta-Utils.html#v:substT" target="_blank">http://hackage.haskell.org/packages/archive/haskell-src-meta/0.5.1.2/doc/html/Language-Haskell-Meta-Utils.html#v:substT</a><br>



<br>
The result would also need to have the context of the instance,<br>
perhaps reduced to just the constraints that mention the type<br>
variables used in the selected function.<br>
<br>
-Michael Sloan<br>
<div><div></div><div><br>
On Fri, Apr 13, 2012 at 11:37 AM, Ismael Figueroa Palet<br>
&lt;<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>&gt; wrote:<br>
&gt; Hi all, I think this is the right place for the following questions and I<br>
&gt; thank beforehand for your answers :-)<br>
&gt;<br>
&gt;<br>
&gt; I&#39;m experimenting with typeclasses and TH, and I want to define a &#39;macro&#39;<br>
&gt; that works more or less like this:<br>
&gt;<br>
&gt; Given the name of a typeclass and a function, return the expressions<br>
&gt; corresponding to the type-annotated instances, for instance<br>
&gt;<br>
&gt; $(foo Show show)<br>
&gt;<br>
&gt; should translate to:<br>
&gt;<br>
&gt; [&quot;(show :: Int -&gt; String)&quot;,  &quot;(show :: Bool -&gt; String)&quot;, ....]<br>
&gt;<br>
&gt; for all instances currently in scope.<br>
&gt;<br>
&gt; I&#39;m currently playing with the isInstance function (I&#39;m running GHC 7.4.1)<br>
&gt; and can get a list of instances, and check if a given type is part of a<br>
&gt; typeclass or not. But I don&#39;t know how to create the expression<br>
&gt; corresponding to &quot;instantiated function&quot;, as above.<br>
&gt;<br>
&gt; Thanks!<br>
&gt; --<br>
&gt; Ismael<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>Ismael<br><br>
</font></span></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Ismael<br><br>
</div>