shapeless-guide icon indicating copy to clipboard operation
shapeless-guide copied to clipboard

Generic `Shape` coproduct types reversed in section 2.4

Open SamDM opened this issue 7 years ago • 2 comments

Near the end of section 2.4 there is the following example:

  sealed trait Shape
  final case class Rectangle(width: Double, height: Double) extends Shape
  final case class Circle(radius: Double) extends Shape

  val gen = Generic[Shape]

gen is supposed to be:

Generic[Shape]{type Repr = Rectangle :+: Circle :+: CNil} = ...

But when I try it, it is (note that Rectangle and Circle are in reversed order):

Generic[Shape]{type Repr = Circle :+: Rectangle :+: CNil} = ...

I am going through the book to learn about shapeless, I don't know if this is intended behavior of shapeless and a bug in the documentation or the other way around. Or does this only happen on my system? If this is a bug in shapeless I'll open an issue there (unless someone beats me to it).

I'm using scala 2.12.3 and shapeless 2.3.2, I'm compiling with sbt.

SamDM avatar Dec 11 '17 23:12 SamDM

Some more experimenting showed that the types are sorted by alphabet instead of order of occurence

SamDM avatar Dec 11 '17 23:12 SamDM

Ah! Good to know. Thanks for the detective work! This must be intentional but I didn’t know it was the case. On Mon, 11 Dec 2017 at 23:21, Sam De Meyer [email protected] wrote:

Some more experimenting showed that the Types are sorted by alphabet instead of order of occurence

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/underscoreio/shapeless-guide/issues/58#issuecomment-350891324, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOI5xzcW3rzBTV7elCMJA5Q-1UpMVtIks5s_bjcgaJpZM4Q-LOg .

davegurnell avatar Dec 12 '17 08:12 davegurnell