newbie question re linear algebra in Haskell
Mon, 18 Nov 2002 11:08:45 -0800
I'm a complete newcomer to Haskell, having learned about only recently.
I'm intrigued by the possibility of in using it for numerical
applications, specifically linear algebra. I understand that (at least
in its present state) Haskell 98 isn't competitive with imperative
languages when it comes to primitive matrix-vector operations, which
often rely on destructive updating. It strikes me that one approach
that takes advantage of the strengths of both paradigms would be create
an imperative subsystem to handle primitive operations, then create a
functional matrix algebra layer on top of it. Based on my very limited
understanding of Haskell, I envision a linear algebra library which
would work something like this:
(1) Create a wrapper for the standard BLAS library. Since an optimized
BLAS is available for various architectures with the same interface,
this would provide a way of optimizing the library for a particular
(2) Encapsulate this (using a monad?) in a way that provides safe access
to the imperative routines from Haskell.
(3) Using this as a foundation, define a matrix algebra in a "smart" way
which avoids redundant evaluations. For instance, if A is an arbitrary
invertible matrix, we know that
A - A = 0
A + 0 = A
A * Indentity = A
A * inverse A = Identity
so if we write an expression like "X = A * inverse A + B - B" we should
expect our library to compute the correct result, "Identity" without
actually performing any inversion, multiplication or elementwise matrix
(4) Create a Haskell module which exposes a pure functional interface,
hiding the imperative subsystem from the user.
My questions are: (a) Is this idea sound? (b) Has someone already done
this? (c) Is there a better way of doing efficient linear algebra in
Haskell? I would greatly appreciate any advice in this regard.