Typeclasses are a pattern that is widespread in functional programming libraries such as cats
and cats-effect. In part one of this workshop we will explore how the mechanics of typeclasses
work in Scala using the Monoid
abstraction as an example. Then, in part two we will cover the patterns of composition defined by
the Functor
, Applicative
and Monad
typeclasses.
In this workshop we will be building everything from first principles. We will not be using any functional programming libraries and will only make minimal use of the scala standard library. By building these constructs from first principles you will understand at a fundamental level how they work, and when they should be applied.
After this workshop you should understand the mechanics of typeclasses, and the composition patterns expressed by Functor
Applicative
and Monad
. This will allow you to effectively make use of similar abstractions libraries such as
cats and provide the foundation to learn about other FP concepts independently.
All the details of the exercises, including reference to the relevant sections of provided code are linked below.
Part 1 – Covers the mechanics of typeclasses.
Part 2 – Covers Functor
, Applicative
and Monad
Solutions – I strongly encourage you to try to solve all the exercises without referring to the solutions.
If you are stuck, please ask a question. However, there are solutions to all the exercises in the solutions
branch
that you can refer to if needed.