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

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