Я сталкиваюсь с этими странными случаями скаляров и матриц, которые ведут себя нечетно в hmatrix. Если я не нахожу аннотацию, операция работает автоматически ala matlab/python. Но если я делаю тип, аннотирую скаляр с помощью «R» или типа или «Double», я получаю ошибку типа.Haskell hmatrix: ошибки типа с векторным/скалярным взаимодействием?
Почему это?
λ> 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]
λ>
Я вижу. поэтому, если кто-то задается вопросом, как его исправить, заменяя одиночные константы элемента (scalar myValue), будет проверять тип вещи – daj