Working with vector
In this recipe, we will look at Data.Vector
from the vector
package. So far, we have been extensively using lists. Though lists are ubiquitous in Haskell, they are not efficient where array-like access and operations are required. A vector supports arrays such as O(1) access to elements, as well as list-like incremental access. The vectors come in two flavors—immutable and mutable. We will look at both in this recipe.
How to do it...
- Create a new project
working-with-vector
with thesimple
Stack template:
stack new working-with-vector simple
- Add the dependency on the
vector
package in thebuild-depends
subsection of the executable section:
executable working-with-vector hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , vector
- Open
src/Main.hs
and start coding there. We will experiment with vector in this...