Hi Yves,<br><br>GHC.Generics [1] and SYB [2] are two rather different approaches to generic programming. There are things that can be done in one but not in the other, and there are things that are easier on one rather than the other. For instance, SYB tends to be very useful for large AST transformations, with functions that have a general behaviour but a couple of particular cases for a few constructors. GHC.Generics, on the other hand, can encode functions such as generic fmap and traverse. It lends itself better to optimisation since it doesn&#39;t use runtime casts, and as such tends to be faster than SYB. It isn&#39;t planned to replace SYB.<br>

<br><br>Cheers,<br>Pedro<br><br>[1] <a href="http://www.haskell.org/haskellwiki/Generics">http://www.haskell.org/haskellwiki/Generics</a><br>[2] <a href="http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB">http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB</a><br>

<br><div class="gmail_quote">On Mon, Mar 12, 2012 at 16:35, Yves Parès <span dir="ltr">&lt;<a href="mailto:yves.pares@gmail.com">yves.pares@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">

I&#39;d have a question concerning GHC.Generics: how does it relate to SYB&#39;s Data.Generics?<br>Is it intended to replace it or complete it?<br>In other words: does class Data.Generics.Data class do things that class GHC.Generics.Generic can&#39;t do?<br>



<br><br><div class="gmail_quote">Le 12 mars 2012 04:27, Reiner Pope <span dir="ltr">&lt;<a href="mailto:reiner.pope@gmail.com" target="_blank">reiner.pope@gmail.com</a>&gt;</span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div class="h5">

<div style="word-wrap:break-word"><div>Hi all,</div><div><br></div>I&#39;ve been playing with GHC&#39;s new generics features (see <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html" target="_blank">http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html</a>). All the documentation I&#39;ve seen suggests creating a &quot;helper class&quot; -- for instance, the GSerialize class in the above link -- on which one defines generic instances. <div>



<br></div><div>It seems to me that this isn&#39;t necessary. For example, here&#39;s the the example from the GHC docs, but without a helper class:</div><div><br></div><div>&gt; -- set the phantom type of Rep to (), to avoid ambiguity</div>



<div>&gt; from0 :: Generic a =&gt; a -&gt; Rep a ()</div><div>&gt; from0 = from</div><div>&gt; </div><div>&gt; data Bit = O | I</div><div>&gt; </div><div>&gt; class Serialize a where</div><div>&gt;   put :: a -&gt; [Bit]</div>



<div>&gt; </div><div>&gt;   default put :: (Generic a, Serialize (Rep a ())) =&gt; a -&gt; [Bit]</div><div>&gt;   put = put . from0</div><div>&gt; </div><div>&gt; instance Serialize (U1 x) where</div><div>&gt;   put U1 = []</div>



<div>&gt; </div><div>&gt; instance (Serialize (a x), Serialize (b x)) =&gt; Serialize ((a :*: b) x) where</div><div>&gt;   put (x :*: y) = put x ++ put y</div><div>&gt; </div><div>&gt; instance (Serialize (a x), Serialize (b x)) =&gt; Serialize ((a :+: b) x) where</div>



<div>&gt;   put (L1 x) = O : put x</div><div>&gt;   put (R1 x) = I : put x</div><div>&gt; </div><div>&gt; instance (Serialize (a x)) =&gt; Serialize (M1 i c a x) where</div><div>&gt;   put (M1 x) = put x</div><div>&gt; </div>



<div>&gt; instance (Serialize a) =&gt; Serialize (K1 i a x) where</div><div>&gt;   put (K1 x) = put x</div><div><br></div><div>Is there a reason to prefer using helper classes? Or perhaps we should update the wiki page (<a href="http://www.haskell.org/haskellwiki/Generics" target="_blank">http://www.haskell.org/haskellwiki/Generics</a>) to avoid using helper classes?</div>



<div><br></div><div>Regards,</div><div>Reiner</div></div><br></div></div><div class="im">_______________________________________________<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></div></blockquote></div><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>
<br></blockquote></div><br>