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

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New

Other popular topics Top

malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New

Sub Categories: