The Writer monad is a sibling of the state and the reader, oriented on modifying the state. Its main purpose is to provide a facility to write into some kind of log by passing this log between computations. The type of the log is not specified, but usually, some structure with a possibly low overhead of the append operation is chosen. To name a few suitable possibilities, you could use a Vector from the standard library or a List. In the case of the List, we need to prepend the log entries and revert the resulting log at the very end.
Before we get too deep into the discussion about the type of log, it is good to realize that we can defer the decision until later. All we need to know is how to append an entry to the existing log. Or, in other words, how to combine two logs, one of which contains just a single entry, together. We already know about the structure with...