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

Popular Pragmatic Bookshelf topics Top

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
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
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
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
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
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New
dachristenson
@mfazio23 Android Studio will not accept anything I do when trying to use the Transformations class, as described on pp. 140-141. Googl...
New

Other popular topics Top

AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New