Shapeless: Introduction resources

Where to start if you want to learn shapeless

Recently I decided to have a better look at shapeless, the generic programming library for scala. In the previous couple of years I had bookmarked several links and have recently read all of them . In this blog post I present the most useful ones for someone who want to be introduced to the library.


The following blog posts are introductory to shapeless. Basically they are a smooth introduction to shapeless , something to warm up

Also these slides on Type-Level Computations in Scala by Stefan Zeiger (not shapeless per se , but a lot of examples for type-level scala, like type-level booleans, type-level natural numbers, translation to types, recursion with types, type functions, type lambdas, heterogenous lists, hlist fold). I tried to find the video talk, but couldn’t find it online.

The Α shapeless primer blog post by Edoardo Vacchi is the best and most complete introductory blog post I could find. It really goes into a lot of explaining hlists, product types, Generic[T], FnToProduct[F] object, implicit value resolution, evidences and typeclasses, the Aux Pattern). There is also a video presentation by the author Edoardo Vacchi (with slides). In this blog post I find very interesting the comparison of Scala with Prolog and how implicit variables, implicit functions, type parameters in functions and implicit parameter lists of functions can be “interpreted” in a rule-based context.

Scala Prolog
implicit vals facts
implicit defs rules
type parameters in def variables in a rule
implicit parameter lists bodies of a rule

In Shapeless? - Easy!, Valentin Kasas explains in a great way an advanced example of a real life use case (computing deltas) (with slides). From this presentation I took the following notes. There are also available two nice blog posts by Valentin : Shapeless : not a tutorial - part 1 (Heterogenous lists, polymorphic function values, high order poly functions) and part 2 (Generic, singleton types, records and LabelledGeneric)

In First-class polymorphic function values in shapeless (2 of 3) — Natural Transformations in Scala, Miles Sabin the creator of shapeless explains the concepts of polymorphic functions and natural transformations.

In the Shapeless for Mortals talk, Sam Halliday explains shapeless fundamentals like : type classes (not shapeless per se , but used extensively when using the library), singleton types, HList, LabelledGeneric, Coproduct, Hipster.Aux (SI-823), Higher Order Unification, Implicit Resolution: Recursion , Cycles and Priority, Tags (Notes from the talk)

The page Shapeless features provides a short overview of the main features of the library : polymorphic function values, heterogenous lists, HList-style operations on standard Scala tuples, facilities for abstracting over arity, heterogenous maps, singleton-typed literals, singleton-typed symbols, extensible records, coproducts and discriminated unions, generic representation of (sealed families of) case classes, boilerplate-free lenses for arbitrary case classes, automatic type class instance derivation, first class lazy values tie implicit recursive knots, collections with statically known sizes, type safe cast(Typeable/TypeCase), testing for non-compilation (illTyped)

After reading Shapeless features , the natural thing to follow is the Scala exercises in shapeless by 47 deg, which is almost identical to Shapeless features, but you will need to fill in the gaps so as to solve the exercises.

A lot of examples are available in Shapeless examples


bonus : Although not shapeless specific, there are two very interesting talks about Lenses