Questions about the vector library, a popular implementation of Int-indexed arrays in Haskell.
Questions tagged [haskell-vector]
14 questions
15
votes
2 answers
Differences between Storable and Unboxed Vectors
So ... I've used unboxed vectors (from the vector package) preferably now without giving it much consideration. vector-th-unbox makes creating instances for them a breeze, so why not.
Now I ran into an instance where it is not possible for me to…

fho
- 6,787
- 26
- 71
6
votes
0 answers
Can Data.Vector's modify ever really be done in place?
In the source for modify it is stated that the operation will be performed in place if it is safe to do so and will modify a copy of the vector otherwise.
But looking at the code for modify:
modify :: Vector v a => (forall s. Mutable v s a -> ST s…

bbarker
- 11,636
- 9
- 38
- 62
2
votes
1 answer
How to unbox vector with 2 values
I am trying to do wilcoxonMatchedPairTest as given here:
import Data.Vector as V
import Statistics.Test.WilcoxonT
sampleA = [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]
main = do
putStrLn "\nResult of…

rnso
- 23,686
- 25
- 112
- 234
2
votes
1 answer
Data.Vector.modify with nested vectors
I have a vector nested inside another. I want to use modify to update this matrix in place. So I use it for the inner vector, but do I also need to use it for the outer?

Lo HaBuyshan
- 359
- 2
- 12
2
votes
0 answers
Do shared mutable vectors synchronize with atomic operations in GHC Haskell?
I'm looking for shared concurrent vectors in Haskell, so I would accept an answer that points to a performant solution other than what I'm discussing here, which is to combine the vector library with stm or atomic-primops.
I have two threads sharing…

Li-yao Xia
- 31,896
- 2
- 33
- 56
2
votes
0 answers
Should I expect Data.Vector to fuse the following function?
I have recently started using Data.Vector. My understanding is that it should be able to take chains of vector operations and efficiently combine them via fusion.
In particular, I would expect these two functions to have similar performance…

Artem Solod
- 417
- 2
- 9
1
vote
1 answer
How do I thaw, mutate, then refreeze a Haskell Vector?
I'm working through a tutorial on Haskell Vectors that, as an exercise, asks you to reimplement Data.Vector.Unboxed.modify using runST and "functions introduced earlier in the tutorial" which I take to be thaw & freeze.
This is what I've…

Tom Steavenson
- 11
- 2
1
vote
1 answer
How to specify the type of a vector of fixed size?
I am trying to use Data.Vector.Fixed as the input to a function and am struggling to specify the vector's dimension in the type signature.
For example, I am trying to do something like the following:
acronym :: Vector (Peano 8) String ->…

mherzl
- 5,624
- 6
- 34
- 75
1
vote
1 answer
Haskell vector type declaration
I'm writing a comparator to pass to sortBy but I can't get the type declaration right. The input is two Data.Vector's, each containing two numbers.
-- Comparator to sort a list of individuals by increasing order of fit-0
-- and for individuals…

tsorn
- 3,365
- 1
- 29
- 48
1
vote
2 answers
Intersperse values into separate Vectors using generate
I am trying to generate a tuple of Vectors by using a function that creates a custom data type (or a tuple) of values from an index. Here is an approach that achieves the desired result:
import Prelude hiding (map, unzip)
import Data.Vector hiding…

lehins
- 9,642
- 2
- 35
- 49
0
votes
1 answer
Unboxed vector of newtype hangs in basicUnsafeNew
I'm trying to store a simple vector of three-dimensional points in space. To do this, I'm newtype-ing a custom Point and manually implement the Data.Vector.Unboxed.Vector and Data.Vector.Unboxed.Mutable instances for it.
However, for some reason,…

Johannes P
- 888
- 8
- 16
0
votes
0 answers
Haskell converting between vector types
I'm starting to learn Haskell, but I'm finding it hard to figure out the small, little things that the tutorials jumps over. Right now I'm working with tuples in the form of Vector.Fixed:
import qualified Data.Vector.Fixed as VF
import qualified…

tsorn
- 3,365
- 1
- 29
- 48
0
votes
4 answers
Haskell create vector with subvectors using indexes
I'm trying to create a vector with subvectors consisting of elements taken out from another vector using a vector of sub-vector indexes.
Each element in b corresponds to the sub-vector-index the elements in a should have when put into c.
import…

tsorn
- 3,365
- 1
- 29
- 48
0
votes
1 answer
Is there a way to avoid UndecidableInstances in this example?
When I try this:
import GHC.Generics (Generic)
import Control.DeepSeq (NFData(..))
import Data.Vector.Generic (Vector)
data Entry a = Entry !Bool a
deriving (Generic, NFData)
-- The variable @v@ is meant to be instantiated with a…

Luis Casillas
- 29,802
- 7
- 49
- 102