尝试使用hmatrix来创建零芯片。 出于某种原因,当我尝试这个命令行,它的工作原理:如何使用hmatrix构建零矩阵?
buildMatrix 2 3 (\(r,c) -> fromIntegral 0)
然而,当我试图做同样的事情在我的代码:
type Dim = (Int, Int)
buildFull :: Matrix Double -> Vector Int -> Vector Int -> Dim -> Int
buildFull matrix basic nonbasic (m, n) = do
-- Build mxn matrix of zeroes
let f = buildMatrix m n (\(r,c) -> fromIntegral 0)
m
失败:
Pivot.hs:23:17:
Ambiguous type variable `a0' in the constraints:
(Element a0) arising from a use of `buildMatrix'
at Pivot.hs:23:17-27
(Num a0) arising from a use of `fromIntegral' at Pivot.hs:23:44-55
Probable fix: add a type signature that fixes these type variable(s)
In the expression: buildMatrix m n (\ (r, c) -> fromIntegral 0)
In an equation for `f':
f = buildMatrix m n (\ (r, c) -> fromIntegral 0)
In the expression:
do { let f = buildMatrix m n (\ (r, c) -> ...);
m }
Failed, modules loaded: none.
这并不完全正确,你需要一个单子结果类型使用做记号。事实上,除了在desugaring过程之后它们是很好的类型之外,符号不会对它所产生的表达式的形式引入任何约束。由于这只会解除“让...在......”,并且不以任何方式涉及>> =或>>运算符,所以这种情况不需要单点返回类型。 – Carl
嗯..我得到'非法签名模式:矩阵 - >双f 使用-XScopedTypeVariables来允许它错误,如果我做第一种方法。 – drozzy
另外'let f = buildMatrix mn 0 :: Double'似乎不工作:“无法匹配预期的类型'(Int,Int) - > a0' 与实际类型'Double' 在第三个参数'buildMatrix',即'(0 :: Double)' 在表达式中:buildMatrix mn(0 :: Double) 在'f'的等式中:f = buildMatrix mn(0 :: Double) 失败,加载模块: 没有。” – drozzy