This series of posts talks about types in the Scala programming language.
In this categoryPosts in this category, from newest to oldest:
Scala offers different programming paradigms, from object oriented programming (OOP) all the way to functional programming (FP). Most Scala developers come from OOP and know OOP classes and inheritance well, but lack familiarity with algebraic data types commonly used in functional programming. In this article we aim to explain algebraic data types and their use in Scala.
We start with a simple formal notion of a type and combine simple types with sum and product types to introduce algebraic data types. We then show how Scala encodes these types, with some comparison to Haskell to illustrate the boilerplate Scala imposes for these types. Noticing similarities between certain combined types we now take a look at generics and isomorphisms between types. We conclude with some remarks about the effects of subtyping which comes with sum types in Scala, and outline how subtyping impacts the ergonomics of sum types in Scala.