1. 15
  1. 7

    Hey everyone, I hope you enjoy this article. I wanted to disclose that I wrote this article in part to promote my book Effective Haskell. I also wrote the article because a lot of people find debugging in Haskell to be tricky, or don’t expect that you can do normal print style debugging in a pure language. I thought having a tutorial for how to use common debugging techniques would be helpful.

    1. 2
       printf "%c (0x%x): %s: Count: %d -> %d" char (ord char) (show $ classifyCharacter char)
         count count
      

      If we run this code, we get exactly what we’d hoped: we’re adding and subtracting when we should be, and we correctly count 4 characters in the file:

      I’m pretty sure what you actually wanted here was:

      printf "%c (0x%x): %s: Count: %d -> %d" char (ord char) (show $ classifyCharacter char) 
        count newCount
      

      Nice article though, I think that Debug.Trace is very underrated when it comes to debugging Haskell code, particularly recursive code. I’ve used this many times in the decade plus I’ve been using Haskell:

      foo x y 
          | traceShow ("foo",x,y) False = undefined
          | otherwise = foo y (x+y)
      

      which gives an output like:

      ("foo",1,1)
      ("foo",1,2)
      ("foo",2,3)
      ("foo",3,5)
      ...
      
    2. 3

      I loved this post. Thank you very much Rebecca. I’m looking forward to the book. I would buy it now on beta but it seems that beta only includes the eBooks. I’m a dead-tree kind of person. I’ll keep my eye out for it!

      1. 1

        How does this whole article manage to not say “grapheme” once?

        1. 2

          I really wanted to keep the article focused on debugging rather than spending more time on unicode terminology than was necessary to follow the example, but I guess I could have added that term in. I noticed a couple of typos in the article as well, so if I have an opportunity to make edits I can try to add an aside if you think the article is worse off for the terminology I used.

          1. 2

            I find that any use of the word “character” can be dangerous in most contexts, but especially since you have to basically explain grapheme clusters anyway (talking about ZWJ etc) it seemed odd to not at least name the thing being explained.