Skip to content

Instantly share code, notes, and snippets.

Olivier Blanvillain OlivierBlanvillain

View GitHub Profile
View playground.scala
import reflect.ClassTag
object playground {
/* All combinations of
* - trait / trait with common / extension trait
* - extending class / extension
* - monomorphic / generic implementation
View build.sbt
lazy val root = project
lazy val `deriving-scalac` =".deriving-scalac"))
scalaVersion := "2.12.99-bin-SNAPSHOT", // published local
scalaSource in Compile := baseDirectory.value / "../deriving/src/main/scala",
View ajax.scala
object Ajax {
def get(url: String, data: InputData = null, timeout: Int = 0,
headers: Map[String, String] = Map.empty,
withCredentials: Boolean = false, responseType: String = "") = {
apply("GET", url, data, timeout, headers, withCredentials, responseType)
def post(url: String, data: InputData = null, timeout: Int = 0,
headers: Map[String, String] = Map.empty,
withCredentials: Boolean = false, responseType: String = "") = {
View final.scala
object Playground extends App {
sealed trait IExp
final case class Lit(i: Int) extends IExp
final case class Neg(e: IExp) extends IExp
final case class Add(r: IExp, l: IExp) extends IExp
sealed trait Tree
final case class Leaf(s: String) extends Tree
final case class Node(s: String, ts: List[Tree]) extends Tree

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](

View typeclasses.scala
// Suppose that this definition:
trait Iterator[A] {
def iter(f: (A) => Unit): Unit
// Desugared into:
trait Iterator[A] {
View build.sbt
scalaVersion := "2.11.8"
scalaOrganization := "org.typelevel"
libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.2"
scalacOptions += "-Yliteral-types"
View two-holes-minimized-si2718-test-case.scala
trait Lift[TC[_], A]
object Lift {
implicit def lift[TC[_], A](implicit t: TC[A]): Lift[TC, A] = null
trait Trait[A, B]
object Trait {
implicit val instance: Trait[String, String] = null
OlivierBlanvillain / TypeLevelBacktrack.scala
Last active Jun 6, 2020
Example of a workaround for the absence of backtracking in implicit resolution. Original problem statement:
View TypeLevelBacktrack.scala
import shapeless.{HList, HNil, ::}
import shapeless.ops.hlist.{Selector, Prepend}
import shapeless.test.illTyped
object TypeLevelBacktrack extends App {
/** [[Parent]] / [[Child]] relationship, father side. */
trait FatherOf[Parent, Child]
/** [[Parent]] / [[Child]] relationship, mother side */
trait MotherOf[Parent, Child]
View DemoOptionT.scala
// Needed to make it work with Future, we could use any Functor instead.
import scala.concurrent.Future
import scalaz.std.scalaFuture._
trait T
trait A
trait B
object DemoOptionT {
You can’t perform that action at this time.