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 it works...

A Writer monad works with an assumption that the write state is an instance of a monoid. As a monoid, you will get two properties:

  • mempty: This is a scratch value
  • mappend: This is a way to combine two values

A Writer monad hence starts with an empty (or scratch) value. As we use the function tell in the context of Writer monad, the Writer monad keeps combining the existing value with a new value and updates the writer state. 

In our recipe, we used Transaction and its monoid instance to keep our balance sheet automatically updated.

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