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-set
using thesimple
Stack template:
stack new working-with-set simple
- In the project folder, open the
working-with-set.cabal
file. Add the new dependencycontainers
in the subsectionbuild-depends
of sectionexecutable
:
executable working-with-set hs-source-dirs: src main-is: Main.lhs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , Containers
The containers
library is a commonly used library that implements containers such as set
, map
, and so on.
- Open
src/Main.hs
for editing. We will work withsets
in this file:
module Main where
- Import
Data.Set
for usingset
and related functions:
import Data.Set as S
- Write
main
; we will writeset
examples in themain
function:
...