I'm trying to use ekmett's linear library, and I'm having some trouble with variable length vectors, in Linear.V. How do I use the dim
function to get the size of a vector? How do I use trace
on a large square matrix made of nested V
s ? I get errors in both of these cases.
Minimal code:
import qualified Data.Vector as Vector
import Linear.V (V(V), dim)
import Linear.Vector (outer)
import Linear.Matrix (trace)
v, w :: V n Double -- What do I do here?
v = V $ Vector.fromList [1..5]
w = V $ Vector.fromList [2, 3, 5, 7, 11]
d = dim v
m = outer v w
t = trace m
It gives these errors which I don't understand:
• Ambiguous type variable ‘n0’ arising from a use of ‘dim’
prevents the constraint ‘(Linear.V.Dim n0)’ from being solved.
Probable fix: use a type annotation to specify what ‘n0’ should be.
These potential instances exist:
two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: dim v
In an equation for ‘d’: d = dim v
• Ambiguous type variable ‘n1’ arising from a use of ‘trace’
prevents the constraint ‘(Linear.V.Dim n1)’ from being solved.
Probable fix: use a type annotation to specify what ‘n1’ should be.
These potential instances exist:
two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: trace m
In an equation for ‘t’: t = trace m