由于 hmatrix 为 Matrix 类型提供了 Num 的实例,我可以表达元素减法,例如:
m = (2><2)[1..] :: Double Matrix
m' = m - 3
这很好用,就像3a一样Num,并且通过从 的每个元素中减去 3 来创建一个矩阵m。
为什么这也不起作用:
m' = m - (3::Double)
我得到的错误是:
Couldn't match expected type ‘Matrix Double’
with actual type ‘Double’
In the second argument of ‘(-)’, namely ‘(3 :: Double)’
In the expression: m - (3 :: Double)
我希望编译器能够理解 aDouble也是Num. 为什么看起来不是这样?