繁体   English   中英

Haskell-hMatrix上的实例声明

[英]Haskell - Instance Declaration on hMatrix

我在列表上使用fromBlocks的fromBlocks函数,其元素由Int-> Int-> Int- Int -> Int -> Int -> Matrix Int类型的函数确定。 但是,GHC抱怨说:

No instance for (Element Int) arising from a use of `fromBlocks'
    Possible fix: add an instance declaration for (Element Int)
    In the expression:
      fromBlocks [[matrixCreate n m d], [rowZero n m d]]

我试图用:: Matrix Int告诉GHC该计算结果的类型,但是它不起作用,而且我不理解如何在使用函数时声明类型。

否-确实没有Element Int实例-参见此处: http : //hackage.haskell.org/package/hmatrix-0.16.0.3/docs/Numeric-LinearAlgebra-HMatrix.html#t : Element Int

如果可以的话,就去Matrix FloatMatrix Double

只需声明一个instance Element Int ,如[1]中所述。 请注意,许多高级功能仅针对DoubleFloat定义。

[1] https://github.com/albertoruiz/hmatrix/issues/28

编辑 :添加阿尔贝托的评论:

instance Element Int

a = (2><3) [1..] :: Matrix Int

z = (1><1) [0] :: Matrix Int

m = fromBlocks [[a,z],[a,a]]

> m

(4><6)
 [ 1, 2, 3, 0, 0, 0
 , 4, 5, 6, 0, 0, 0
 , 1, 2, 3, 1, 2, 3
 , 4, 5, 6, 4, 5, 6 ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM