Shopping cart as a set
In this recipe, we will create a shopping cart for books. The books are uniquely identified by ISBN numbers. If we add the same item in the shopping cart, we should be able to update the existing item or insert a new item in the shopping cart. We will use set as a container for shopping items.
How to do it...
- Create a new project
shopping-cartusing thesimpleStack template:
stack new shopping-cart simple
- Open
shopping-cart.cabaland add a dependency on thecontainerslibrary in thebuild-dependssubsection of theexecutablesubsection:
executable shopping-cart
hs-source-dirs: src
main-is: Main.lhs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, containers- Open
src/Main.hs; we will add our code here. Import the moduleData.Set:
module Main where
import Data.Set as Set- Create a type to represent a book. The book contains the...