使用fromList

时间:2016-08-09 17:51:16

标签: haskell

我正在尝试使用Data.Vector.SEXP模块。我是Haskell的新手。 以下是我的所作所为:

> let x = Data.Vector.SEXP.fromList [2,3]

<interactive>:35:5:
    Non type-variable argument in the constraint: Num (ElemRep s ty)
    (Use FlexibleContexts to permit this)
    When checking that ‘x’ has the inferred type
      x :: forall s (ty :: Foreign.R.Type.SEXPTYPE).
           (ty
            Foreign.R.Constraints.:∈ '['Foreign.R.Type.Char,
                                       'Foreign.R.Type.Logical, 'Foreign.R.Type.Int,
                                       'Foreign.R.Type.Real, 'Foreign.R.Type.Complex,
                                       'Foreign.R.Type.String, 'Foreign.R.Type.Vector,
                                       'Foreign.R.Type.Expr, 'Foreign.R.Type.WeakRef,
                                       'Foreign.R.Type.Raw],
            Num (ElemRep s ty), Storable (ElemRep s ty),
            Data.Singletons.SingI ty) =>
           Data.Vector.SEXP.Vector s ty (ElemRep s ty)

我迷路了。我想要一个从列表中创建的SEXP向量的示例。

2 个答案:

答案 0 :(得分:2)

尝试这样做:

> let x = Data.Vector.SEXP.fromList ([2,3] :: [Int])

问题是在Haskell中,数字文字被重载,因此[2,3]的类型为Num a => [a],而不是[Int]

答案 1 :(得分:0)

HaskllR unittests采取的另一种方法是具体的数据类型

import qualified Foreign.R as R
import qualified Data.Vector.SEXP as V

idVec :: V.Vector s 'R.Real Double -> V.Vector s 'R.Real Double
idVec = id

然后:

let v = idVec $ V.fromList [-1.9,-0.1,-2.9]