Types in Scala

This series of posts talks about types in the Scala programming language.

In this category

Posts in this category, from newest to oldest:
  • Algebraic Data Types In Scala
    Published Feb 24, 2018. Last revised Mar 20, 2018. In categories: article, types-in-scala, scala

    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.