How to do it...

  1. Create a new project work-with-map using the simple stack template.

  2. Add the containers library to the build-depends subsection of the executable subsection:
        executable working-with-map
          hs-source-dirs:      src
          main-is:             Main.hs
          default-language:    Haskell2010
          build-depends:       base >= 4.7 && < 5
                         , containers
  1. Open src/Main.hs; we will use this as our playground for dealing with map:
        module Main where
  1. Import Data.Map to use the map functions. We will use the strict version of map:
        import Data.Map.Strict as M
  1. We will use the main function directly to work with map functions:
        main :: IO ()
        main = do  
  1. Map Construction--Create an empty map or a map with a single entry:
 let e = M.empty :: Map Int Int let s = M.singleton 1 "Haskell ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.