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"><<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>></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"><<a href="mailto:mgsloan@gmail.com" target="_blank">mgsloan@gmail.com</a>></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 "reifyInstances" 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>
<<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>> wrote:<br>
> Hi all, I think this is the right place for the following questions and I<br>
> thank beforehand for your answers :-)<br>
><br>
><br>
> I'm experimenting with typeclasses and TH, and I want to define a 'macro'<br>
> that works more or less like this:<br>
><br>
> Given the name of a typeclass and a function, return the expressions<br>
> corresponding to the type-annotated instances, for instance<br>
><br>
> $(foo Show show)<br>
><br>
> should translate to:<br>
><br>
> ["(show :: Int -> String)", "(show :: Bool -> String)", ....]<br>
><br>
> for all instances currently in scope.<br>
><br>
> I'm currently playing with the isInstance function (I'm running GHC 7.4.1)<br>
> and can get a list of instances, and check if a given type is part of a<br>
> typeclass or not. But I don't know how to create the expression<br>
> corresponding to "instantiated function", as above.<br>
><br>
> Thanks!<br>
> --<br>
> Ismael<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><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>