Haskell hmatrix:vector/scalar 交互输入错误?

Haskell hmatrix: type errors with vector/scalar interactions?

我 运行 研究了标量和矩阵在 hmatrix 中表现奇怪的这些奇怪情况。如果我不输入 annotate,该操作会自动运行 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]
λ> 

我认为它已记录在案 here

Autoconformable dimensions

In most operations, single-element vectors and matrices (created from numeric literals or using scalar), and matrices with just one row or column, automatically expand to match the dimensions of the other operand

您必须匹配类型和大小,但是您的注释类型是标量,期望第二个操作数中有向量。