# Revamping the numeric classes

**Ch. A. Herrmann
**
herrmann@infosun.fmi.uni-passau.de

*Wed, 7 Feb 2001 10:12:10 +0100 (MET)*

moved to haskell-cafe
Ketil> E.g. way back, I wrote a simple differential equation solver.
Ketil> Now, the same function *could* have been applied to vector
Ketil> functions, except that I'd have to decide on how to implement
Ketil> all the "Num" stuff that really didn't fit well. Ideally, a
Ketil> nice class design would infer, or at least allow me to
Ketil> specify, the mathematical constraints inherent in an
Ketil> algorithm, and let my implementation work with any data
Ketil> satisfying those constraints.
the problem is that the --majority, I suppose?-- of mathematicians
tend to overload operators. They use "*" for matrix-matrix
multiplication as well as for matrix-vector multiplication etc.
Therefore, a quick solution that implements groups, monoids, Abelian
groups, rings, Euclidean rings, fields, etc. will not be sufficient.
I don't think that it is acceptable for a language like Haskell
to permit the user to overload predefined operators, like "*".
A cheap solution could be to define a type MathObject and operators like
:*: MathObject -> MathObject -> MathObject
Then, the user can implement:
a :*: b = case (a,b) of
(Matrix x, Matrix y) -> foo
(Matrix x, Vector y) -> bar
--
Christoph Herrmann
E-mail: herrmann@fmi.uni-passau.de
WWW: http://brahms.fmi.uni-passau.de/cl/staff/herrmann.html