我正在尝试使用ekmett的线性库,但在Linear.V中我遇到了可变长度向量的问题。如何使用该dim
函数获取向量的大小?如何在由嵌套strace
组成的大型方阵上使用?V
在这两种情况下我都会出错。
最小代码:
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
它给出了这些我不明白的错误:
• 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