O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required