[Haskell-cafe] Are storable-mutable-vectors in two dimensions possible in Haskell?

Dmitry Dzhus dima at dzhus.org
Sat Dec 1 12:27:56 CET 2012


01.12.2012, 15:14, "Fixie Fixie" <fixie.fixie at rocketmail.com>:
> Hello haskellers
> I am struggling with this package: Data.Vector.Storable.Mutable
> I am creating vectors like this: MV.new 1000 :: IO (V.MVector (PrimState IO) Int)
> Now I would like access to this vectors in linear time, like I could have done in C using pointers.
> The problem is that I do not know which datastructure to keep my vectors in. If I put them in a list, the access is very slow. Even a binary tree is very slow compared to a C-version.
> I have tried to make an array og vector of storable-mutable vectors, but have not manged to accomplish this - even though there must be a haskell way :-)

You can use boxed vector as a first-level structure holding pointers
you your storable vectors to perform O(1) indexing on first dimension.

Alternatively, if your matrix is dense, store your data in a
one-dimensional vector and use Repa as a thin wrapper to perform
multi-dimensional indexing (see toIndex/fromIndex
Data.Array.Repa.Shape).



More information about the Haskell-Cafe mailing list