Marc van Dongen wrote:
> I am not quite sure how to express this in Haskell
> terms but here it goes anyway: Why is :% in Ratio
> not hidden?
>
> By allowing a user program to construct elements of
> the form (a:%b) one can create objects which lead to
> inconsistencies
...
> (-1:%1) < (0:%1) < (1:%-1) == (-1:%1),
> The last equality follows from (3) and the fact that:
> (1:%-1) <= (-1:%1) and (-1:%1) <= (1:%-1).
> Using (2) it now follows that (-1:%1) < (-1:%1) which
> according to (1) should not be true.
>
> According to the language definition (1:%-1) != (-1:%1).
====
First of all: at least in Hugs (:%) is *not* exported by
the Prelude.
So, it is hidden, and a sane, well educated gentleman would
not procreate a fraction with negative denominator.
The form (1:%-1) is an abomination. Perhaps less than (1:%0),
but anyway. But how to have a low-level efficiency and a
direct access to data structures, and the respect of all
mathematic constraints? In principle we could have a polar
representation of complexes: (r,theta), and somebody really
funny could put a negative r inside.
And then somebody really sad would cry that (r,theta) is equal
but not really, to (r,theta+2PI).
The only safe way of dealing with it is to use a brutal
screening of the constructor and the selectors, to make them
private, to use OO methods to access everything. The automatic
derivation of Eq is obviously silly, but I don't think we would
like to abandon its simplicity.
Jerzy Karczmarczuk
Caen, France