1

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.

guaraqe
  • 249
  • 1
  • 7

2 Answers2

1

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

Random Dev
  • 51,810
  • 9
  • 92
  • 119
0

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 ]
vivian
  • 1,434
  • 1
  • 10
  • 13
  • That's correct. You can do something like this: 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 ] But there are very few useful operations for Int elements. – Alberto Ruiz Jun 27 '14 at 07:02