Revamping the numeric classes

Andreas Gruenbacher
Tue, 6 Feb 2001 22:29:36 +0100 (CET)

On Tue, 6 Feb 2001, Dylan Thurston wrote:

> On Tue, Feb 06, 2001 at 03:25:11PM +0100, Koen Claessen wrote:
> > What do people think about this? If people prefer these
> > stylistic changes, I think we should not hesitate making
> > them for Haskell/2 by completely redesigning the module
> > structure and using more consistent naming conventions.
> These sound great to me.  If Haskell/2 is indeed open to such changes,
> would also be possible to revamp the numeric modules?  As a
> mathematician, I get annoyed by such things as
> * (+) and (-) being lumped in with (*) (doesn't anyone use vector spaces?)

That also causes me some headaches.

For various number-like algebras (*) is not even defined. Not defining it
in an instance of Num leads to annoying runtime errors that would
otherwise be caught at compile time. For others algebras (*) is
self-multiplication (t -> t -> t). Even for others, it might be scaling (s
-> t -> t).

It may be the case that using (*) for scaling too is a generally bad

Another problem: The right place for fromInteger is probably not in class
Num. One cannot use the remaining Num operations on everything one can
construct from an Integer.
Otherwise it would be possible to write `0' for different kinds of zero
elements (and perhaps `1' for different one elements), even for things on
a nominal scale.

> * the function 'atan2' being mixed in with a bunch of operations very
>   specific to the floating point format in the 'RealFloat' class.
>   Same problem (though less serious) with 'quot', etc., and
>   'toInteger' in the Integral class.
> * Superfluous superclasses: why are Show and Eq superclasses of Num?
>   Not all numeric types have decidable equality.  Think arbitrary
>   precision reals.

Also not all instances of Num can be shown. I have a monad that is an
instance of Num, for example. I cannot possibly show the monad.

> (I saw Mechvelliani's Basic Algebra Proposal; it strikes me as being
> too complicated for the task.)
> Best,
> 	Dylan Thurston

Andreas Gruenbacher.

 Andreas Gruenbacher        
 Research Assistant                       Phone      +43(1)58801-12723
 Institute for Geoinformation             Fax        +43(1)58801-12799
 Technical University of Vienna           Cell phone   +43(664)4064789