O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a new project shopping-cart using the simple Stack template:
        stack new shopping-cart simple
  1. Open shopping-cart.cabal and add a dependency on the containers library in the build-depends subsection of the executable subsection:
        executable shopping-cart
         hs-source-dirs:      src
         main-is:             Main.lhs
         default-language:    Haskell2010
         build-depends:       base >= 4.7 && < 5
                       , containers
  1. Open src/Main.hs; we will add our code here. Import the module Data.Set:
        module Main where

        import Data.Set as Set
  1. Create a type to represent a book. The book contains the ISBN number, title of the book, and name of the author:
        data Book = Book { isbn :: String
                 , title :: String
                 , author :: String }
                   deriving Show
  1. Create the equality and ordering ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required