Aux pattern

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:...

January 29, 2020

Typesafe reflection

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:...

January 22, 2020

GADTS in a nutshell

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:...

November 30, 2019

Blog revamping

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....

November 22, 2019