guaraqe
guaraqe

Reputation: 249

Haskell - Type incompatibility after qualified import

I'm using hMatrix and the first lines of my code are:

import Numeric.LinearAlgebra
import qualified Data.Vector as V

The problem is that in my code the vector type is V.Vector, but some methods defined by hMatrix have type Vector -> ... and GHC does not understand when I try to use these methods, saying that they are not defined for the type V.Vector. How can I solve this problem?

Update:

From the documentation of hMatrix:

The Vector type is a Storable vector from Roman Leshchinskiy’s vector package, so all array processing tools provided by this library are directly available.

However, some basic operators like (++) (which is present in Data.Vector.Storable) are not included in hMatrix. Is it impossible to use these from hMatrix or is there some simple way to tell the compiler that these types are the same?

Upvotes: 1

Views: 148

Answers (3)

choener
choener

Reputation: 321

Note that you can't break hmatrix just because you import another module. You just have a type mismatch as vector provides different types of vectors, including a .Generic interface that works for all of those.

You probably have something along the lines of

import Data.Vector
f :: Vector Int -> Vector Int
f = whatever

If you import Data.Vector.Generic you can write functions that work for all vector types, including those used by hmatrix.

import Data.Vector.Generic
f :: Vector Int -> Vector Int
f xs = xs ++ empty

should work with hmatrix vectors.

Upvotes: 1

snak
snak

Reputation: 6703

hmatrix uses its own Data.Packed.Vector type and it's different from Data.Vector.

Either using Data.Packed.Vector in your code, or converting Data.Vector to Data.Packed.Vector before calling functions would work.

Upvotes: 3

Nadir Sampaoli
Nadir Sampaoli

Reputation: 5555

You could add an explicit import for the Vector type:

import Numeric.LinearAlgebra
import qualified Data.Vector as V
import Data.Vector (Vector)

Though, I didn't know external modules could break depending on how you import modules they depend on.

Upvotes: 1

Related Questions