How to do it...

  1. Create a new project working-with-vector with the simple Stack template:
        stack new working-with-vector simple
  1. Add the dependency on the vector package in the build-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
  1. Open src/Main.hs and start coding there. We will experiment with vector in this file:
        module Main where
  1. Import both immutable and mutable vector modules:
        import qualified Data.Vector as V
        import qualified Data.Vector.Mutable as MV
        import Data.Vector ((//),(!),(!?))
  1. We will use smaller functions to demonstrate the vector and its abilities.
  2. Construction: We can construct ...

Get Haskell Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.