Questions regarding Bounded

Simon Jakobi simon.jakobi at googlemail.com
Wed May 6 17:51:28 UTC 2020


Dear Henning,

I've re-read your email now and thought about it a bit more.

> Unfortunately, Ord is dual use:
>
> 1. Comparison for magnitude as suggested by the mathematical symbols (<)
> and (>).
>
> 2. Some arbitrary but total order for use in Set and Map.
>
> E.g. Set (Complex a) makes total sense, but 1:+0 > 0:+1 is unexpected. Ord
> instances on pairs is sensible for Set and Map, but (max (1,0) (0,1) ==
> (1,0)) is strange.

Personally, I find nothing strange about (max (1,0) (0,1) == (1,0)),
but I started wondering how other languages handle these examples. I
tried Python:

$ python3
Python 3.5.2 (default, Apr 16 2020, 17:47:17)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> max((1,0),(0,1))
(1, 0)
>>> complex(1,0) > complex(0,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: complex() > complex()

I also find the Ord Maybe instance quite intuitive: "Nothing is less
than something (Just)"

It is also consistent with the interpretation of Maybe as a list of at
most one element:

$ ghci
> [] < [()]
True

So in my view the Bounded Maybe instance still seems like a good idea.

Cheers,
Simon


More information about the Libraries mailing list