Given this example:
abstract class Base { type Value }
case object Foo extends Base { type Value = String }
case class Bar[A <: Base](a: A, value: A#Value)
val x = Bar(Foo, "It's a Foo") // Won't compile with found String required ?#Value
I would like to have the type constraint for value to be the same as the type for A. I.e. String since I'm passing in Foo. I know I can model this differently, but it would be nice to know if it's at all possible?
As a starting point this compiles and provides some of the constraint you require.
abstract class Base { type Value }
case object Foo extends Base { type Value = String }
case class Bar[A <: Base, V <: A#Value](a: A, value: V)
val x = Bar(Foo, "It's a Foo")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With