Break `abs` into two aspects

Carter Schonwald carter.schonwald at gmail.com
Fri Jan 31 21:36:01 UTC 2020


that actually sounds pretty sane. I think!

On Fri, Jan 31, 2020 at 3:38 PM Andrew Lelechenko <
andrew.lelechenko at gmail.com> wrote:

> On Tue, 28 Jan 2020, Dannyu NDos wrote:
>
> > Second, I suggest to move `abs` and `signum` from `Num` to `Floating`
>
> I can fully relate your frustration with `abs` and `signum` (and numeric
> type classes in Haskell altogether). But IMO breaking both in `Num` and in
> `Floating` at once is not a promising way to make things proper.
>
> I would rather follow the beaten track of Applicative Monad and Semigroup
> Monoid proposals and - as a first step - introduce a superclass (probably,
> borrowing the design from `semirings` package):
>
> class Semiring a where
>   zero  :: a
>   plus  :: a -> a -> a
>   one   :: a
>   times :: a -> a -> a
>   fromNatural :: Natural -> a
> class Semiring a => Num a where ...
>
> Tangible benefits in `base` include:
> a) instance Semiring Bool,
> b) a total instance Semiring Natural (in contrast to a partial instance
> Num Natural),
> c) instance Num a => Semiring (Complex a) (in contrast to instance
> RealFloat a => Num (Complex a)),
> d) newtypes Sum and Product would require only Semiring constraint instead
> of Num.
>
> Best regards,
> Andrew
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200131/3a124120/attachment.html>


More information about the Libraries mailing list