I'm using the function fromBlocks
from hMatrix over a list whose elements are determined by functions of type Int -> Int -> Int -> Matrix Int
. However, GHC complains saying that:
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]]
I tried to tell GHC the type of the result of this computation with :: Matrix Int
but it didn't work, and I don't understand how to declare the type when using the function.
No - there is really no instance for Element Int
- see here: http://hackage.haskell.org/package/hmatrix-0.16.0.3/docs/Numeric-LinearAlgebra-HMatrix.html#t:Element
Just go for Matrix Float
or Matrix Double
if you can
Just declare an instance Element Int
as described in [1]. Be warned that many of the fancier functions are only defined for Double
and Float
.
[1] https://github.com/albertoruiz/hmatrix/issues/28
Edit : add Alberto's comment:
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 ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.