Variance is a topic that may be pretty confusing at first and which results from introducing subtyping into a programming language. The whole question asked by Variance is simple though. Given a type A and its subtype B, can one be safely substituted for the other without affecting the program correctness? John De Goes has recently made two Spartan sessions about this topic, and we will cover some of the thoughts he shared during these....
In this post, we will demonstrate a technique called type refinement (Aux pattern) that was covered in a Spartan session by John De Goes.
We would like to solve the following problem: Given a Member and a Family, we would like to make sure a Selection is valid at compile-time. A Selection is valid only if the Member provided belongs to the Family passed in parameter.
case class Member(name: String) sealed trait Family case class Selection(family: Family, member: Member) A first approach consists in providing a type parameter:...
Following the previous post, here is a nice technique to implement typesafe reflection using GADTs.
As you may know, Scala provides us with Phantom types. A Phantom type is parameterized type which the only purpose is to provide type-safety and which is erased at runtime:
/* A is only present as a type parameter but is not used anywhere else in the structure definition */ case class Foo[A](name: String) This can be used to tag a type with some additional metadata used by the compiler to ensure type-safety:...
I recently attended a training provided by John De Goes about Generalized Algebraic Data Types (GADTs) and wanted to make a quick recap of what those are.
An Algebraic Data Type (ADT) is a sum type built from a collection of sum/product types:
sealed trait Foo object Foo { case class Bar() extends Foo } In order to make this ADT polymorphic, we have to introduce type parameters in some of the terms of the ADT:...
This blog got created some years ago but has never been really maintained (Mostly because of a lack of time). Nonetheless I recently decided to document what I work and learn about and to use this blog for that.I gave a very cool talk about microservices at the Techno-Drink meetup recently, and really enjoyed my time. Thank you guys for hosting this event and allowing me to talk. Slides are available here....