Effective Haskell Chapter 10

In Chapter 10, in the section in “Building A Basic Metrics System with IORefs” after the new type Metrics is introduced in the text, it isn’t used in the code (AppMetrics is still used as the type). I suspect a mismatch between refactoring text and code.

The displayMetrics function is described but the code is missing.

When I ran directorySummaryWithMetrics, if I ran it on a very large directory it failed with too many open file handles (I definitely need to finish the chapter and read ups on the pitfalls of lazy IO :)). When I ran it on smaller directories, all the timings were 0. I ended up looking at the code for timeIt and rewrote the timing code to use getCPUTime (returning the seconds as a double); all the timing were fractions of seconds!

Were you still hitting the too many file descriptors error on the later versions of the function? There’s an intentional error in the earlier versions that are used to demonstrate the lazy IO problem, but it’s possible there’s still a bug lurking in the later iterations.

Overall, this is kind of a tough chapter because so many of the filesystem related examples are going to depend on system specific things like what your OS happens to have cached in memory, the speed of your disk, type of filesystem, etc I think your general intuition to experiment with the examples on your own system is the right one.