我在列表上使用来自hMatrix的函数Int -> Int -> Int -> Matrix 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这个计算结果的类型,但是它没有起作用,而且我不知道如何在使用这个函数时声明这个类型。
发布于 2014-06-25 09:32:15
不-实际上没有Element Int的实例-参见:http://hackage.haskell.org/package/hmatrix-0.16.0.3/docs/Numeric-LinearAlgebra-HMatrix.html#t:Element
如果可以的话,只要选择Matrix Float或Matrix Double就行了
发布于 2014-06-26 19:57:30
如1所述,只需声明一个instance Element Int。请注意,许多高级函数只为Double和Float定义。
编辑:添加阿尔贝托的评论:
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 ]https://stackoverflow.com/questions/24404844
复制相似问题