Haskell linear algebra libraries that are polymorphic with classes of the genus *

I want to use a linear algebra library with netwire. Since the types netwire are instances Applicative, it provides copies Numand Fractionalfor its type that automatically liftA2perform the desired function. This is nice because you can do something like multiply time-varying values ​​without any extra effort.

I used linear, but its functions are defined as not polymorphic in type *, i.e. matrix product:

(!*!) :: (Functor m, Foldable t, Additive t, Additive n, Num a)
    => m (t a) -> t (n a) -> m (n a)

This means that if I am not mistaken, I cannot determine the instances for the Additivecompany, because there is no reasonable form for the instance. Although I can write

instance Num b => Num (Wire s e m a b) where ...

no way to write

instance Additive n => Additive (Wire s e m a (n x)) where ...

(Wire s e m a (n x)) (* * -> *). , , .

, *?

Vec, .

(Map v v' m1 m3, Map v a b v', Transpose m2 b, Fold v a, Num v, Num a)
    => m1 -> m2 -> m3

. ?

+4
2

vector-space, , , (VectorSpace ).

, , , linear, Foldables . (, , , )

instance (AdditiveGroup a) => AdditiveGroup (Wire a) where
  ...

instance (VectorSpace v) => VectorSpace (Wire v) where
  type Scalar (Wire v) = Scalar v  -- Or perhaps `Wire (Scalar v)`
  ...
+3

, :

  • hmatrix - ; * -> *, GPL
  • vect - OpenGL; ; , , dot, .
  • Vec - ; (. ); ; OpenGL
  • linear - ; GLUtil -gl; * -> *
  • - - ; ; OpenGL, ; , ,
  • - OpenGL;
  • - ; ; , , (.. Matrix (Wire s e m a Double) - ); OpenGL

, Vec, . ( , ). , Vec , , , , . , , .

OpenGL ( , Storable). , / (.. rotationX :: Floating a => a -> Mat44 a). , Vec.

: Vec . , , . , Fold.

: Wire s.

+1

Source: https://habr.com/ru/post/1530904/


All Articles