kittens is a Scala library which provides instances of type classes from the Cats library for arbitrary algebraic data types using shapeless-based automatic type class derivation. It also provides some utility functions related to cats.Applicative such as lift, traverse and sequence to HList, Record and arbitrary parameter list.

This will respect all existing instances even if the field is a type constructor. For example Show[List[A]] will use the native Show instance for List and derived instance for A. And it manually caches the result to the val showFoo. Downside user will need to write one for every type they directly need a Show instance

There are 3 alternatives:

full auto:

importderived.auto.show._

The downside is that it will re-derive for every use site, which multiples the compilation time cost.

full auto cached

importderived.cached.show._

Use this one with caution. It caches the derived instance globally. So it's only applicable if the instance is global in the application. This could be problematic for libraries, which has no control over the uniqueness of an instance on use site. It relies on shapeless.Cached which is buggy. Mile Sabin is working on a language level mechanism for instance sharing.

manual semi

implicitvalshowFoo:Show[Foo] = derived.semi.show

It has the same downside as the recommenced semi-auto practice but also suffers from the type constructor field issue. I.e. if a field type is a type constructor whose native instance relies on the instance of the parameter type, this approach will by default derive an instance for the type constructor one. To overcome this user have to first derive the instance for type parameter. e.g. given

caseclassFoo(bars: List[Bar])
caseclassBar(a: String)

Since the bars field of Foo is a List of Bar which breaks the chains of auto derivation, you will need to derive Bar first and then Foo

kittens and Typelevel Scala

Typelevel Scala provides a partial fix for SI-7046 which can present obstacles to the uses of shapeless's Generic and LabelledGeneric for the sealed trait at the root of an ADT such as you find in Kittens. If it appears that these two type classes are unable to find (all of) the subclasses of an ADT root trait then please try using Typelevel Scala and see if it resolves the issue.

To use Typelevel Scala you should,

Update your project/build.properties to require SBT 0.13.13 or later,

sbt.version=0.13.13

Add the following to your build.sbt immediately next to where you set scalaVersion,

scalaOrganization := "org.typelevel"

If this does resolve the problem, please lend your support to the pull request being merged in Lightbend Scala.

Participation

The Kittens project supports the Typelevelcode of conduct and wants all of its channels (mailing list, Gitter, github, etc.) to be welcoming environments for everyone.

Building kittens

kittens is built with SBT 0.13.9 or later, and its master branch is built with Scala 2.11.7 by default.