- Create a new project write-trans using the simple Stack template.
- 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
- Open src/Main.hs. We will edit this file for our purpose.
- Add the following imports after initial module declaration for the WriterT monad transformer:
import Data.Monoid import Control.Monad.Writer
- Add the data type Transaction. We 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 ...