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: [cc escaped="true" lang='scala' ] sealed abstract class List[+A] { def head : A def ::[B >: A] (x:B) : List[B] = ... ... } [/cc] And you've probably heard that the +A means that A is a "covariant type parameter",

Continue reading »