Working with sets
In this recipe, we will work with a set and its APIs. A set is a container that stores unique ordered values.
How to do it...
- Create a new project
working-with-setusing thesimpleStack template:
stack new working-with-set simple
- In the project folder, open the
working-with-set.cabalfile. Add the new dependencycontainersin the subsectionbuild-dependsof sectionexecutable:
executable working-with-set
hs-source-dirs: src
main-is: Main.lhs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, ContainersThe containers library is a commonly used library that implements containers such as set, map, and so on.
- Open
src/Main.hsfor editing. We will work withsetsin this file:
module Main where
- Import
Data.Setfor usingsetand related functions:
import Data.Set as S
- Write
main; we will writesetexamples in themainfunction:
...