Haskell Matrix Library...

Henning Thielemann lemming at henning-thielemann.de
Sun Jun 26 15:25:17 EDT 2005

On Sun, 26 Jun 2005, Benjamin Franksen wrote:

> On Sunday 26 June 2005 19:22, Henning Thielemann wrote:
> > The reason why these operators are methods of classes
> > is that it shall be possible to write mathematical expressions which
> > can be universally used for different types of numbers, such as
> > Float, Double, Rational, Integer and so on. Prelude's class framework
> > is oriented at the scalar types it provides. My concern is: Are
> > matrices a natural extension of these scalar types? What is
> > (fromInteger 1) for the matrix class? The identity matrix or the
> > matrix which consists entirely of ones?
> The identity matrix, of course.

Certainly not "of course", because e.g. 'exp' and 'sin' are "of course"
applied element-wise in the library proposal.

Thus e.g.  exp (fromScalar 0) == fromScalar (exp 0)
 is no longer true. (fromInteger does not work for this example, but you
see the problem in principle.)

> The real problem is the dimension, which we would like to have as an
> extra type argument and this is incompatible with the Prelude.

Btw. it is not good to code a fixed matrix size into the type because
there are many applications where the size is not known at compile time.
The only thing we should assert is that the sizes of matrices in an
operation fit together. A general type signature like

matrix_mul :: Num a => Matrix i j a -> Matrix j k a -> Matrix i k a

is a step towards this goal. Making it really type-safe sounds like the
implicit configuration problem.

More information about the Libraries mailing list