softwaremill / magnolia

Easy, fast, transparent generic derivation of typeclass instances
https://softwaremill.com/open-source/
Apache License 2.0
761 stars 116 forks source link

Structural decomposition leads to endless loop #50

Open joroKr21 opened 6 years ago

joroKr21 commented 6 years ago

Here's some food for thought:

// Adapted from [Okasaki 1996]
sealed trait LSeq[+A]
case object LNil extends LSeq[Nothing]
case class LCons[+A](head: A, tail: LSeq[(A, A)]) extends LSeq[A]
Show.gen[LSeq[Int]].show(LCons(1, LCons(2 -> 3, LNil)))

... still waiting for typer ... (maybe it will OOM eventually)

A problem for most type class derivation libs. I know why this happens but not sure what can be done. The hammer for endless loops is a (configurable?) max depth. Is there a better way?

propensive commented 6 years ago

Yes, that's an interesting case. It wouldn't be impossible to include a configurable limit, but it seems like a hack, so I'm not sure it's the best solution.

Other ideas welcome...

joroKr21 commented 6 years ago

Miles solved it in his byname implicits PR scala/scala#6050