In what way is it not a number?<br><br>data MyNumber a = MyNum a a<br>   deriving (Show, Eq)<br><br>instance Functor MyNum where<br>  fmap f (MyNum a b) = MyNum (f a) (f b)<br><br>instance Applicative MyNum where<br>  pure a = MyNum a a<br>
  MyNum f g &lt;*&gt; MyNum a b = MyNum (f a) (g b)  <br><br>instance (Num a) =&gt; Num (MyNum a) where<br>  a + b = pure (+) &lt;*&gt; a &lt;*&gt; b<br>  a - b = pure (-) &lt;*&gt; a &lt;*&gt; b<br>  a * b = pure (*) &lt;*&gt; a &lt;*&gt; b<br>
  negate a = pure negate &lt;*&gt; a<br>  abs a = pure abs &lt;*&gt; a<br>  signum = fmap signum<br>  fromInteger = pure . fromInteger<br><br>This instance obeys the commutative, distributive, and associative laws,  and the multiplicative, and additive identities. (at least, if the numbers it contains satisfy those laws)<br>
How is MyNum not a number?<br><br><br>Sönke Hahn: <br>  btw, I forgot to mention in my first email, but <br>      fromInteger n = (r, r) where r = fromInteger n<br>  is better than:<br>      fromInteger n = (fromInteger n, 0)<br>
 as you get a lot of corner cases otherwise.<br><br> I use fromInteger = pure . fromInteger, which when combined with my Applicative instance, is effectively the same as your:  fromInteger n = (r, r)  where r = fromInteger n<br>
  <br><br>- Job<br><br><div class="gmail_quote">On Mon, Oct 5, 2009 at 9:12 AM, Miguel Mitrofanov <span dir="ltr">&lt;<a href="mailto:miguelimo38@yandex.ru">miguelimo38@yandex.ru</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"><br>
<br>
Sönke Hahn wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I used to implement<br>
<br>
    fromInteger n = (r, r) where r = fromInteger n<br>
<br>
, but thinking about it, <br>
    fromInteger n = (fromInteger n, 0)<br>
<br>
seems very reasonable, too. <br>
</blockquote>
<br></div>
Stop pretending something is a number when it&#39;s not.<div><div></div><div class="h5"><br>
_______________________________________________<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>
</div></div></blockquote></div><br>