<div><div dir="auto">Derp. :)</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 5, 2020 at 9:08 PM Zemyla <<a href="mailto:zemyla@gmail.com">zemyla@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">"i" is an Integer there, which has an Ord instance.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 5, 2020, 19:20 Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Num doesn't have Ord as a parent constraint any more ... Though i suppose that works as a default signature instance?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 5, 2020 at 3:19 PM Mario Blažević <<a href="mailto:mblazevic@stilo.com" rel="noreferrer" target="_blank">mblazevic@stilo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2020-02-04 11:32 a.m., Zemyla wrote:<br>
> It really doesn't matter if it's not "interesting" or not surjective for <br>
> some Semirings. It should be included, because:<br>
<br>
        I fully agree, and I'll add another reason you left out. The presence <br>
of fromNatural would allow defaulting of Num's fromInteger as<br>
<br>
 > fromInteger i<br>
 >     | i >= 0 = fromNatural (fromInteger i)<br>
 >     | otherwise = negate . fromInteger . negate $ i<br>
<br>
<br>
> (a) Even for semirings where it is "interesting", it's not surjective <br>
> (for instance, Rational or Double)<br>
> (b) It's a method with a default definition, so you don't have to expend <br>
> any mental effort on it<br>
> (c) A lot of instances have uninteresting methods: for instance, (*>) <br>
> and (<*) for Applicative ((->) e) are const id and const respectively. <br>
> Haskell adds methods to classes when they're always possible and <br>
> sometimes useful/interesting/faster, rather than when they're always <br>
> interesting.<br>
> (d) It's useful for Semiring-generic methods and instances.<br>
> (e) It can achieve an asymptotic speedup on some instances. Like, if you <br>
> have Semiring a => Semiring (f a) for some type f, then you can have <br>
> fromNatural n = pure (fromNatural n) instead of doing the whole O(log n) <br>
> song and dance with the default definition. Also, your example admits a <br>
> simple definition:<br>
>    fromNatural n = if n == 0 then S.empty else S.singleton True<br>
> (f) "zero" and "one" can be defined in terms of fromNatural, for <br>
> programmers who only need to define that:<br>
>    zero = fromNatural 0<br>
>    one = fromNatural 1<br>
> This leads to the MINIMAL pragma on Semiring being {-# MINIMAL plus, <br>
> times, (zero, one | fromNatural) #-}<br>
> (g) If it's not included in the class, but in some subclass <br>
> (NaturalSemiring, you proposed), but it's possible from the class, then <br>
> people will just define and use the O(log n) version instead of <br>
> requiring the subclass, leading to wasted effort and duplicated code.<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div></div>