Stéphane Laurent
Stéphane Laurent

Reputation: 84529

Create a SEXP vector using fromList

I'm trying to use the Data.Vector.SEXP module. I am a newbie in Haskell. Here is what I do and get:

> 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)

I am lost. I'd like to have an example of a SEXP vector created from a list.

Upvotes: 2

Views: 104

Answers (2)

pyCthon
pyCthon

Reputation: 12341

Another way taken from the HaskllR unittests is to specific a data type

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

Then:

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

Upvotes: 0

Alec
Alec

Reputation: 32309

Try doing this instead:

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

The problem is that in Haskell, number literals are overloaded, so [2,3] has type Num a => [a] instead of [Int].

Upvotes: 2

Related Questions