[Haskell-cafe] Re: Statically dimension-checked hmatrix
Patrick Perry
patperry at stanford.edu
Tue Nov 18 04:00:01 EST 2008
> What is the situation regarding statically dimension-checked linear
> algebra libraries? It seems that Frederik Eaton was working on one in
> 2006 (see the paper "Statically typed linear algebra in Haskell"), and
> he produced the Vectro library from this, based on GSLHaskell.
>
> Are there any more recent efforts into this, particularly using the
> new TFs? If not, I might have a go at it, as a thin wrapper for
> hmatrix.
The BLAS bindings I wrote use phantom types to make sure the
dimensions are consistent. See, for example the functions to get row
and column views of a matrix:
http://hackage.haskell.org/packages/archive/blas/0.6/doc/html/Data-Matrix-Dense-Class.html#v%3ArowViews
Also, the multiplication routines:
http://hackage.haskell.org/packages/archive/blas/0.6/doc/html/BLAS-Matrix-Immutable.html
I've found that phantom types are a good trade off: they provide
enough type safety to catch common mistakes without being too much of
a hassle to use. Another benefit (which I didn't anticipate) is that
they help a *lot* with documentation.
I'm skeptical of value that comes from stronger typing. At some point
the types become too much of a hassle to be worth using. Even phantom
types get in the way sometimes and require use of either GADTs,
unsafeCoerce, or both, which is annoying.
I'd be interested to hear about any developments you make in this area.
Patrick
p.s. If you're interested in trying it out, the version of blas on
hackage doesn't compile with ghc-6.10.1, but the version in the darcs
repository at http://stat.stanford.edu/~patperry/code/blas does.
More information about the Haskell-Cafe
mailing list