Bounded and floating types

Yitzchak Gale gale at sefer.org
Wed Dec 5 05:10:10 EST 2007


Wolfram wrote:
> My arguments consistently assume the following specification:
> \begin{spec}
> forall a . (Ord a, Bounded a) =>
>   forall x :: a . minBound <= x && x <= maxBound
> \end{spec}

That sounds like a great thing to suggest for Haskell'. It is
not true currently. Ord and Bounded are independent of
each other. Current discussions on this list make it clear
that forcibly enforcing such a restriction, e.g. by
introducing Bounded instances in libraries, would break
people's existing programs.

Your restriction implies, among other things, that Ord may
only be used for natural universal orderings of a type, not for
arbitrary artificial orderings introduced for technical reasons.
Because otherwise, why restrict people from using a
natural Bounded instance if there is one, or a Bounded
instance that is needed for some other technical reason?

A good migration path towards your idea would be to
fix the current most prominent offenders, the Data.<collection>
modules, by providing an additional version of each that
uses Indexable instead of Ord for artificial orderings, as
suggest by Henning.

And, of course, there is nothing to stop us from suggesting
that people adhere to your specification by adding it
to the documentation.

I wrote:
>> Where are these axioms?

> ...it could be argued that the sentence: "The Bounded class
> is used to name the upper and lower limits of a type."
> might be understood to imply it

Given the current usage of Ord in the libraries, there is no reason
to think that the upper and lower limits *of a type* necessarily
have anything to do with Ord.

-Yitz


More information about the Libraries mailing list