Due to a limitation in the way Shapeless' describe
is currently
implemented, Show
can't be derived for ADTs which are _both_
recursive _and_ generic in one or more type parameters.
Due to a limitation in the way Shapeless' describe
is currently
implemented, Show
can't be derived for ADTs which are _both_
recursive _and_ generic in one or more type parameters.
See: https://github.com/typelevel/kittens/pull/48#issue-249836267 https://github.com/milessabin/shapeless/issues/750
See the test suite for more precise examples of what can and cannot be derived.
Fully automatically derive the instance, note that this derivation is not cached, so it will re-derive every time an instance is needed in the application, which could significantly impact the compilation time.
cached cache the derived instance but this cache are global, so be cautious only use it when there is only one instance globally in your application.
allows semi automatically derive each instance.
allows semi automatically derive each instance. The derivation might need help when there are fields with type constructor that comes with instances e.g.
scala> case class Foo(bars: List[Bar]) scala> case class Bar(a: String) scala> cats.derived.semi.show[Foo].show(Foo(List(Bar("a")))) res1: String = Foo(bars = $colon$colon(head = Bar(a = a), tl$access$1 = Nil.type()))
Note that semi.show didn't respect the native Show[List]
instance
You could either derive a Bar instance first
scala> implicit val barShow = cats.derived.semi.show[Bar] scala> cats.derived.semi.show[Foo].show(Foo(List(Bar("a")))) res2: String = Foo(bars = List(Bar(a = a)))
Or you can take advantage of a controlled auto derivation
scala> implicit val fooShow: Show[Foo] = { | import cats.derived.auto.show._ | cats.derived.semi.show | } scala> Foo(List(Bar("a"))).show res3: String = Foo(bars = List(Bar(a = a)))