<div dir="ltr">Hello,<br><br><div class="gmail_quote">On Fri, Sep 5, 2008 at 14:34, Jules Bean <span dir="ltr">&lt;<a href="mailto:jules@jellybean.co.uk">jules@jellybean.co.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d">José Pedro Magalhães wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Complex has a derived instance. In Data.Complex:<br>
<br>
 &nbsp; &nbsp;data (RealFloat a) =&gt; Complex a<br>
 &nbsp; &nbsp; &nbsp;= !a :+ !a &nbsp;  &nbsp; &nbsp;# if __GLASGOW_HASKELL__<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deriving (Eq, Show, Read, Data)<br>
 &nbsp; &nbsp;# else<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deriving (Eq, Show, Read)<br>
 &nbsp; &nbsp;# endif<br>
<br>
Was there a problem with this?<br>
<br>
</blockquote>
<br></div>
Yes, isn&#39;t it exactly the same problem as Ratio?<br>
<br>
The derived instance &#39;leaks&#39; the implementation detail of a complex number as a real and imaginary component. As part of a large structure I might want to apply some operation to all the &#39;Doubles&#39; therein, but certainly not to the components of any Complex Doubles. You can imagine particular situations where I want to apply only to the real component, or something more subtle.<br>

<br>
You can also imagine that an alternative implementation of Complexes in polar coordinates (with a suitable solution to the principle value problem) is supposed to be abstractly the same, but would gain a totally different Data instance.</blockquote>
<div><br></div><div><div>I think the question here is if the datatype if abstract or not. Complex exports its (:+) constructor, so the implementation details are not hidden. Therefore it is correct to traverse its arguments.&nbsp;Ratio, however, does not export its (:%) constructor: Ratio is abstract, while Complex is not.</div>
<div><br></div><div>I guess then Complex should have a Data instance as it is above.</div><div><br></div><div>But regarding Ratio, do we want to change its gfoldl to match its current gunfoldl (as suggested before), or go the other way around, and change its&nbsp;gunfold, toConstr and dataTypeOf to match its gfoldl?&nbsp;</div>
<div><br></div><div>If we change its gfoldl, the instance is fully defined, but does not respect the data abstraction.</div><div><br></div><div>If we go the other way around, the instance becomes partial (gunfold and toConstr return errors), but respects the data abstraction.</div>
</div></div><div class="gmail_quote"><div><div><br></div><div>In any case, the&nbsp;behaviour&nbsp;would differ from the current. Any opinions on this?</div><div><br></div><div><br></div><div>Thanks,</div><div>Pedro</div></div></div>
</div>