• Partially evaluating CPP macros in Haskell codebases

    The Haskell Language Server (HLS) codebase has a lot of CPP conditionals. A lot of them look like this:

    #if MIN_VERSION_ghc(9,2,0)
    

    which says that the version of the ghc library has to be at least 9.2; or this

    #if MIN_VERSION_ghc(9,2,0) && !MIN_VERSION_ghc(9,3,0)
    

    which says that the version of the ghc library has to be between 9.2 and 9.3; or this

    #if __GLASGOW_HASKELL__ < 902
    

    which says that the version of GHC itself has to be less than 9.2.

    When we stop supporting a version of GHC, many of these conditonals become obsolete. If we have code like this:

    x = 
    #if MIN_VERSION_GHC(9,2,0)
      1
    #else
      2
    #endif
    

    then once we only support GHC 9.2 and above, the conditional will always evaluate to true, and so we can simplify it away. Until now, we’ve mostly done this by hand. But surely there should be a way to do this automatically!

    Read on →

  • Everything Everywhere All At Once

    It was good, but I didn’t find myself as blown away as some people seem to have been. I did have some thoughts, so here they are (spoilers!).

    Read on →

  • Lenses for Tree Traversals Redux

    Previously I wrote about how you can use explicit Traversals from lens to simplify some aspects of tree manipulation. I recently had another win using this, so here’s another case study! It also provides a better example for when you want to fold over things than the previous post had.

    Read on →

  • On Commenting Code

    Programmers like to go on about how you should or should not comment your code. This is my contribution. But first, go read Antirez’s take on this which is fantastic and says almost everything that needs to be said, I agree with essentially all of it.

    Read on →

  • Four lenses on the upsides of bad behaviour

    I’ve been reading quite a few psychiatric/therapeutic/self-help books recently. This post is some notes on a common thread I noticed in a few of them about the positive sides of “bad” behaviours.

    Read on →