<br><br><div class="gmail_quote">On Mon, Oct 5, 2009 at 11:02 AM, Sönke Hahn <span dir="ltr">&lt;<a href="mailto:shahn@cs.tu-berlin.de">shahn@cs.tu-berlin.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">&gt;<br>
&gt; On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:<br>
&gt; &gt; OK, &quot;just pairs&quot; have no arithmetic, but one way of defining<br>
&gt; &gt; arithmetic is to treat the pairs as complex numbers.  Or as mantissa<br>
&gt; &gt; and exponent.  Or as something else.  So there&#39;s nothing wrong, IMO,<br>
&gt; &gt; to make pairs an instance of Num if you so desire.  (Though I&#39;d<br>
&gt; &gt; probably introduce a new type.)<br>
<br>
</div>I was looking for one intuitive way of instantiating pairs of numbers as Num.<br>
One where i wouldn&#39;t have to look in the documentation to remember what (+)<br>
does. So considering all these examples of what pairs of numbers could be, i<br>
agree with Miguel Mitrofanov: &quot;It&#39;s something that should not be done.&quot;<br>
<br>
Two questions remain, i think:<br>
<br>
1. How can i have some notion of addition and subtraction for something that i<br>
don&#39;t want to put in the Num class?<br>
<br>
That&#39;s easy: I could just write a class that defines binary operators (like<br>
(+~) and (-~), for example). I don&#39;t get  the fanciness of (+), but that&#39;s<br>
okay.<br></blockquote><div><br>I don&#39;t know how well it works in practice, but you could hide the prelude in your module and then import it qualified.  This would allow your module to redefine the normal symbols as the operators you want them to be.<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
2. How can i use numeric literals to construct values, whose types are not in<br>
the Num class?<br></blockquote><div><br>This I don&#39;t know how to do without a pre-processor or maybe Template Haskell would work.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
Haskell could provide a class IsNumber (like IsString for string literals). Is<br>
that something we would want?<br></blockquote><div><br>Seems like IsBoolean would also be useful if you went this route.  And perhaps, IsList :)  I&#39;m sure we could think of more.  I can see how they would be handy for anyone making an eDSL, especially if combine with view patterns.<br>
<br>Jason<br></div></div>