haskell - 使用 fromList 创建 SEXP 向量

标签 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 向量的示例。

最佳答案

尝试这样做:

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

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

关于haskell - 使用 fromList 创建 SEXP 向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38857382/

相关文章:

haskell - Haskell 中的通用 'unwrap' 函数?

haskell - 如何在本地为我的 cabal 包生成网页预览?

haskell - 如何使用 :? 在 ghci 中查找所有函数列表和手册

haskell - [Int] 之和导致溢出

sorting - 如何在两个坐标上对图像大小进行排序?

oop - 如何在 Haskell 中设计一个带有状态的 "web spider"?

haskell - 收集有关现有树状数据的数据

haskell - Scotty:连接池作为单子(monad)阅读器

haskell - 如何定义 listTree 使其在线性时间内运行?

list - Haskell:使用(柯里和)计算列表的长度