Sunday, November 26, 2017

Revisiting Polymorphism: It is more than Inheritance and Subtyping

This post is part of the Type class knowledge pack series in which I explore the pattern for encoding Type classes in Scala. This post will be about polymorphism.

But why Polymorphism you might ask? isn't this series about the Type class pattern? Why do we have a single post dedicated to Polymorphism?

As it turned out, the type class pattern is really just one approach to writing polymorphic code.

And from experience, having a more in-depth appreciation for what Polymorphism is, will go a long way in understanding the why and how of the Type class pattern: which is why, before I go into the actual mechanism of encoding the Type class pattern in Scala, I think it will be of utmost benefit to first explore polymorphism.


Exploring Type class in Scala: A knowledge pack

This series of blog post seeks to provide an exhaustive exploration of the Type-class pattern in Scala.

Aptly described as a "knowledge pack", it won't only touch on the actual mechanism of encoding the type-class pattern in Scala, but it will also explore a bit of the underlining idea behind the pattern and the various language features that come together to make it possible to encode it the way it is done in Scala.

The reason for taking this approach is borne out of my own experience while trying to grok the concept.

I quickly discovered, as anybody new to Scala will do, that the idea of Type classes is widely used in Scala: both in the standard library and in popular third-party libraries. Thus it is imperative to have a good working knowledge of how it works, to be able to effectively use/read code/libraries that make use of the pattern.