Dear Henning,

Thank you for your response! I think I have caused some confusion by not being quite clear in my email. Sorry!

base _does_ contain Ord instances for both Maybe and Either. So the question of what the smallest (Maybe Int8) is, is settled: It's Nothing.

My question is, why the corresponding Bounded instances are missing from base. After all they could simply re-use the bounds implied by the Ord instances.

Thanks,
Simon



Am Mo., 4. Mai 2020 um 15:30 Uhr schrieb Henning Thielemann <lemming@henning-thielemann.de>:

On Mon, 4 May 2020, Simon Jakobi via Libraries wrote:

> Possibly relatedly, I was looking for Bounded instances for Maybe and
> Either. To me the following instances seem sensible:
>
> instance Bounded a => Bounded (Maybe a) where
>    minBound = Nothing
>    maxBound = Just maxBound
>
> instance (Bounded a, Bounded b) => Bounded (Either a b) where
>   minBound = Left minBound
>   maxBound = Right maxBound
>
> Are these instances omitted for a reason? Interestingly, both types do have corresponding Ord instances.

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.

I would not interpret too much into (Bounded a => Maybe a). Nothing may
mean "smaller than any Just element", but it may also mean "larger than
any Just element" or "no regular element at all".

Consider a refactoring where a numeric value is extended by Maybe. Do we
want that comparisons and bounds are silently re-interpreted or would we
like to be alerted that comparisons and bounds don't make sense anymore?
I'd prefer the alert. Unfortunately, Ord Maybe is already defined.

For an extra largest or smallest element I would define a custom
Maybe-like datatype.