liveBook · Manning

Log

As explained in Learn Haskell by Example

An event log is an ordered record of events produced during computation.

An activity log is an ordered collection of events produced while an application runs. In a file-synchronization tool, it records successful copies, failures, and files skipped because synchronization was unnecessary. section 15.0 section 15.1.2

Model each event with a dedicated data constructor, then wrap the list in a newtype. The log can serve as the output accumulated by WriterT, while Semigroup and Monoid instances combine entries from separate computations. section 15.1.2

Printing a synchronization log

printLog :: Log -> IO () printLog (Log xs) = forM_ xs (putStrLn . prettyEntry) A command-line run can produce lines such as "[*] fileA.txt" for success, "[!] file.txt: exception" for failure, and "[s] file.txt: reason" for skipped work.

How Learn Haskell by Example covers it

How deep it goes
Defines event constructors, a list wrapper, accumulation instances, and formatted output, but does not develop persistent log storage.
Examples
Uses file-copy success, IOException failure, skipped files, and a verbose synchronization run as concrete examples.
What it assumes
Assumes basic Haskell data types and IO while introducing WriterT output collection, newtypes, and derived type-class instances.
What you can do after
Build it from scratch with typed entries, WriterT accumulation, derived combination instances, and optional formatted printing.
How it connects
Connects WriterT, Monoid, Semigroup, exception handling, and command-line arguments.

Also explained in

Compare how 14 books explain log →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.