10
votes

I am trying to do some OpenGL programming in haskell. But i am confused by the current state of the libraries. OpenGL uses the Tensor package which only defines several vector types (but doesn't do so in a generic way). It doesn't seem to provide any Matrix implementations.

There are several other packages for linear algebra: tensor (note the lowercase T), Vec, hmatrix which seem to be more complete than Tensor.

What i am searching for should at least contain common functions used in 3d and 2d graphics, have reasonable performance and should be compatible with OpenGL but i guess i'll have to change the library for that.

2
There's also vect, which has OpenGL integration built-in.Ptharien's Flame
vect does look usable. But i think it is far from being a nice (generic) haskell library. Actually it looks alot like Java VecMath where every algorithm is declared for every vector type.fho
I think you should write your own. Being able to criticize other implementations means you're ready for it. I was in a similar situation once and tarried for a long while, but in the end it was time that was worth spending.user1095108
@Ptharien'sFlame, from vect sources: instance Matrix Mat4 where ... inverse = error "inverse/Mat4: not implemented yet". That's not very useful...Karolis Juodelė

2 Answers

2
votes

Late answer, sorry. HMatrix is the standard choice for things like this. It's very compatible, has a nice API, and is actually used for computer vision among other applications: http://dis.um.es/profesores/alberto/research.html

1
votes

I was wondering the same recently, and was especially annoyed that Tensor doesn't provide you with convenient functions for dot product, cross product, normalization etc.

As you pointed out, vect is "hardcoded" for Float and Double, and therfore cannot have useful typeclass instances like Functor, Monoid or Applicative - with those we would get a lot of operations "for free", e.g. addition: (+) <$> v1 <*> v2.

On #haskell, I was pointed to the linear package. It is well-maintained and comes with a bunch of useful instances and functions.