Haskell Matrix Library...

Benjamin Franksen benjamin.franksen at bessy.de
Sun Jun 26 20:39:46 EDT 2005

On Sunday 26 June 2005 21:25, Henning Thielemann wrote:
> 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.

I wasn't refering to the library proposal. And element-wise definitions 
of 'exp' and 'sin' for matrices may be natural in certain contexts, but 
certainly not as /the/ general definition.

> 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.)

Yea, this is ugly and inconsistent. I'd rather use explicit lifting to 
express that a numeric function should be applied element-wise. BTW, 
isn't Matrix a functor over Num so we can use fmap for lifting? Ah, 
doesn't work because of the extra Num constraint, grrr...

> > 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.
>  http://www.eecs.harvard.edu/~ccshan/prepose/prepose.pdf

Yes, Matrix dimensions is a good example, one where the author's 
solution isn't too involved, since dimension is a plain integer.


More information about the Libraries mailing list