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 write-trans using the simple Stack template.
  1. Open write-trans.cabal and add the mtl dependency in the build-depends subsection of the executable section:
        executable write-trans        hs-source-dirs: src        main-is: Main.hs        default-language: Haskell2010        build-depends: base >= 4.7 && < 5               , mtl
  1. Open src/Main.hs. We will edit this file for our purpose.
  2. Add the following imports after initial module declaration for the WriterT monad transformer:
        import Data.Monoid        import Control.Monad.Writer
  1. Add the data type TransactionWe will also add a monoid instance for the Transaction
       newtype Transaction = Transaction Double deriving Show

Add the monoid instance. We will define an empty transaction as a transaction ...

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