andre

andre

Effective Haskell: Chapter 10 - directorySummaryWithMetrics (B9 - PDF version)

@rebeccaskinner

On p.386, we have the final version of directorySummaryWithMetrics.

When running the code, we see the histogram results with empty characters.
It looks like this


Histogram Data:
 : 9091
    : 59
 : 23
 : 1
    : 2
  : 59
 : 12900
    : 643147
 : 20
  : 22
 : 563
  : 6
     : 666771
    !: 1476
    ": 137317
    #: 7367

    ...

The non-printable characters do not display. You can see the empty fields above ASCII value 20 (a total of 666771 spaces here).

Here are the last few lines of the function:

   histogram <- readIORef histogramRef
   putStrLn "Histogram Data:"
   for_ (Map.toList histogram) $ \(letter, count) ->
       putStrLn $ printf "  %c: %d" letter count

   displayMetrics metrics

I suggest to add a check using isControl.

import qualified Data.Char as Char (isControl)
   
   ...

   histogram <- readIORef histogramRef
   putStrLn "\n\nHistogram Data:"                    -- Added "\n\n"
   for_ (Map.toList histogram) $ \(letter, count) ->
      if Char.isControl letter then                   -- Added if .. then ...
           putStrLn $ printf "  %d: %d" letter count
      else
           putStrLn $ printf "  %c: %d" letter count

   displayMetrics metrics


Andre

Where Next?

Popular Pragmatic Bookshelf topics Top

jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New

Sub Categories: