Newtype wrapper for Float/Double with sensible Eq/Ord instances

chessai . chessai1996 at gmail.com
Sat Nov 30 18:35:25 UTC 2019


I would argue there is no "sensible" implementation of Eq and Ord for
floating point. Better to have PartialEq [1] /PartialOrd [2].

[1]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html

[2]: https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html

On Sat, Nov 30, 2019, 11:21 AM Zemyla <zemyla at gmail.com> wrote:

> There should be a newtype wrapper that wraps a RealFloat, keeps the
> Enum/Num/Fractional/so on instances, but gives it sensible ones for Eq and
> Ord, with the following order:
>
> NaN < -Inf < negative < -0 < +0 < positive < +Inf
>
> It may not belong in base, but if nothing else it definitely belongs in
> containers, because Set and Map depend critically on sensible instances of
> Ord.
>
> (Also, it should newtype derive Read and Show, so that people using them
> with GHCi see "fromList [(NaN, yadda), (-1.5, yadda), (2.7, blah), (+Inf,
> blah)]" instead of "fromList [(FloatOrd { unwrapFloat :: NaN }, yadda),
> ...".)
> _______________________________________________
> 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/20191130/ec2343c6/attachment.html>


More information about the Libraries mailing list