Hi,<br><br>I&#39;m not sure I fully understand what you&#39;re trying to do, but when I read<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">

Ideally, I&#39;d like to restrict my<br>
search to Located instances that wrap an instance of Outputable,<br></blockquote><br>I think this means SYB is not the right tool. Due to the way Typeable works (it&#39;s monomorphic), SYB doesn&#39;t really play well with adhoc cases for types which satisfy given class constraints. Your adhoc cases have to be listed per type, a bit like in the empty function [1], for instance.<br>

<br>Also, SYB and parametrized types don&#39;t really mix all that well either. This affects things like extracting all the `b`s from a `Located b`. Perhaps you could have a look at the new generics in GHC 7.2 [2]? You should be able to derive `Generic` for all the GHC API types (using standalone deriving), and this mechanism deals fine with (single) parametrized types. I&#39;d be happy to hear what happens if you try this.<br>

<br><br>Cheers,<br>Pedro<br><br>[1] <a href="http://hackage.haskell.org/packages/archive/syb/latest/doc/html/src/Data-Generics-Builders.html#empty">http://hackage.haskell.org/packages/archive/syb/latest/doc/html/src/Data-Generics-Builders.html#empty</a><br>

[2] <a href="http://www.haskell.org/haskellwiki/Generics">http://www.haskell.org/haskellwiki/Generics</a><br><br><div class="gmail_quote">On Thu, Aug 11, 2011 at 17:56, JP Moresmau <span dir="ltr">&lt;<a href="mailto:jpmoresmau@gmail.com">jpmoresmau@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello, I&#39;m banging my head against a wall there trying to use the syb<br>
generics schemes against the GHC API. I&#39;m looking at implementing a<br>
search mechanism in the AST in the more direct way that what Scion<br>
does (creating an instance of a TypeClass for each AST node type).<br>
Since the GHC AST types derive from Data and Typeable, I thought it<br>
would be possible.<br>
So the problem is a follows: I have a start type, say<br>
TypecheckedSource, that derives from Data. What I&#39;d like to do is to<br>
find all instances of the Located type inside that source that span a<br>
particular range. The problem is that Located is a parametrized type<br>
that wraps anything and just add location information. So the result<br>
of the search could be anything. Ideally, I&#39;d like to restrict my<br>
search to Located instances that wrap an instance of Outputable,<br>
pretty print that and output only the result.<br>
So I&#39;m looking to implement something that would have that signature:<br>
TypecheckedSource -&gt; (Line,Column) -&gt; [String]<br>
<br>
I have written code along these lines:<br>
everything (++) ([] `mkQ` overlap) ts<br>
   where<br>
        overlap :: forall b1 . (Outputable b1, Typeable b1) =&gt;Located<br>
b1  -&gt; [String]<br>
        overlap (a::Located b1)= ... trivial code here finding if the<br>
location overlaps, and if it does, pretty print the object, otherwise<br>
returns []<br>
<br>
And GHC complains:<br>
 Ambiguous type variable `b10&#39; in the constraints:<br>
   (Outputable b10) arising from a use of `overlap&#39;<br>
                    at ...<br>
   (Typeable b10) arising from a use of `overlap&#39;<br>
                    at ...<br>
<br>
So it doesn&#39;t like the fact that I don&#39;t know which types my Located<br>
instances wrap. But that&#39;s the point, I don&#39;t care, I just want to<br>
restrict my search to the ones I can pretty print. If I just try the<br>
code against simple non parametrized types it of course works. If I<br>
add some forall b1 . (Outputable ... in my main function signature it<br>
complains that I never use b1 anywhere else in the signature, of<br>
course.<br>
<br>
Is there a way to achieve what I want<br>
(-XOhPleaseDoWhatIwantEvenIfIamNotSureItMakesSense or something)?<br>
<br>
Thanks a million!<br>
<font color="#888888"><br>
--<br>
JP Moresmau<br>
<a href="http://jpmoresmau.blogspot.com/" target="_blank">http://jpmoresmau.blogspot.com/</a><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>
</font></blockquote></div><br>