I wanted to get deeper into type level programming in Scala and I started doing some small exercises. I started with an implementation of Peano numbers at the type level. Here is the code below!
sealed trait PeanoNumType { // Type at the end indicates to the reader that we are dealing with types
type plus[That <: PeanoNumType] <: PeanoNumType
}
sealed trait ZeroType extends PeanoNumType {
type plus[That <: PeanoNumType] = That
}
sealed trait NextType[This <: PeanoNumType] extends PeanoNumType {
type plus[That <: PeanoNumType] = NextType[This#plus[That]]
}
Now the question is, what would the above implementation buy me? How can I make use of it?