Working with maps
In this recipe, we will look at Data.Map. A map keeps an association between the key and the corresponding value. The map stores the ordered keys and their values (dictionaries). There are two variants of Map in the container library, strict and lazy. In this recipe, we will look at the strict variant. The lazy variant has the same interface, except that the implementation is lazy.
How to do it...
Create a new project
work-with-mapusing thesimplestack template.- Add the
containerslibrary to thebuild-dependssubsection 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.Mapto use themapfunctions. We will use the strict version of map...