Create a new project work-with-map using the simple stack template.
- 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
- Open src/Main.hs; we will use this as our playground for dealing with map:
module Main where
- Import Data.Map to use the map functions. We will use the strict version of map:
import Data.Map.Strict as M
- We will use the main function directly to work with map functions:
main :: IO () main = do
- 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 ...