我遇到了这些奇怪的标量和矩阵在 hmatrix 中表现奇怪的情况。如果我不键入注释,则该操作会自动运行 ala matlab/python。但是,如果我确实使用“R”或类型或“Double”对标量进行类型注释,则会出现类型错误。
为什么是这样?
λ> 4 + ([1,2,3] :: Vector R)
[5.0,6.0,7.0]
λ> (4 :: R) + ([1,2,3] :: Vector R)
<interactive>:155:14:
Couldn't match type ‘Vector R’ with ‘Double’
Expected type: R
Actual type: Vector R
In the second argument of ‘(+)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: R) + ([1, 2, 3] :: Vector R)
In an equation for ‘it’: it = (4 :: R) + ([1, 2, 3] :: Vector R)
λ> (4 :: Double) + ([1,2,3] :: Vector R)
<interactive>:156:19:
Couldn't match expected type ‘Double’ with actual type ‘Vector R’
In the second argument of ‘(+)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: Double) + ([1, 2, 3] :: Vector R)
In an equation for ‘it’:
it = (4 :: Double) + ([1, 2, 3] :: Vector R)
λ> (4 :: R) * ([1,2,3] :: Vector R)
<interactive>:157:14:
Couldn't match type ‘Vector R’ with ‘Double’
Expected type: R
Actual type: Vector R
In the second argument of ‘(*)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: R) * ([1, 2, 3] :: Vector R)
In an equation for ‘it’: it = (4 :: R) * ([1, 2, 3] :: Vector R)
λ> 4 * ([1,2,3] :: Vector R)
[4.0,8.0,12.0]
λ>