November 13, 2013

What part of List don't you understand?

This may be the thing I’m best known for, for better or worse. It started as an honest investigation of the Scala collections library and just got more and more ridiculous. I was tracing the inhertiance hierarchy of Scala’s List, drawing a chart on the fly. And by the time I finished I figured others would find it amusing. Here is the tweet with a link to the chart:

And here is a smaller version just so you can get a sense for the nuttiness. The punchline is that Scala’s cons list has more than thirty superclasses.

The claim is that the complex class structure provides much of your implementation for free, allowing easy construction of new collection types (Martin even jumps in here). But it’s just silly. Extending Scala collections is essentially impossible.

So, I got inspired by this and decided to implement a principled cons list. The end result (with essential contributions from @S11001001 and @xuwei-k) is IList which is now part of scalaz. It is far simpler and strictly superior to Scala’s List, so I encourage you to check it out.