• Using the free monad to avoid stack overflows in Scala

    The code for this post can be downloaded here.

    One of the joys of Scala is actually being able to code in a much more functional style than you can in Java. But inevitably as you start down that route you start using the machinery of advanced functional programming: monads, monad transformers and their ilk.

    So it’s a bit of a shock when what looks like some perfectly innocent code stack overflows in your face.

    Read on →

  • Australia update 3

    Once again, it’s been far too long since I updated this, but better late than never!

    Read on →

  • Slides for variance talk

    I gave my post as a talk at the recent ScalaSyd, and you can get the slides here.

    As an aside, I made the somewhat hand-wavy allegation that the normal Hom-functor that we use is in some way the “right” one. I sat down to actually try to prove this, and I haven’t been able to come up with anything satisfactory. On the face of it, there’s no reason why there shouldn’t be other functors that behave the same as the Hom-functor on objects, but do something different to the arrows. So unless there’s a cunning proof that there can’t be such a functor in generality, or there’s an independent characterisation of the Hom-functor that I haven’t thought of, I’m a bit stumped.

    Ideas welcome!

  • The master argument for Effective Altruism

    [epistemic status: mostly believed, high confidence]

    I was putting together some readings about effective altruism, and I realised that the resources I’d picked out nicely mirror and support the stages of a prototypical argument for effective altruism.

    Read on →

  • Covariance and contravariance in Scala

    I spent some time trying to figure out co- and contra-variance in Scala, and it turns out to be both interesting enough to be worth blogging about, and subtle enough that doing so will test my understanding!

    So, you’ve probably seen classes in scala that look a bit like this:

    sealed abstract class List[+A] {
        def head : A
        def ::[B >: A](x : B) : List[B] = ...
        ...
    }
    

    And you’ve probably heard that the +A means that A is a “covariant type parameter”, whatever that means. And if you’ve tried to use classes with co- or contra-variant type parameters, you’ve probably run into cryptic errors about “covariant positions” and other such gibberish. Hopefully, by the end of this post, you’ll have some idea what that all means.

    Read on →