Unfortunately, types are not first class citizens in Scala. This means, for example, that you cannot match patterns by type. A lot of information is lost due to a silly erasure of a type inherited from the Java platform.
I do not know if there are any improvements for this, but this is one of the worst problems in my version, so someone should really come up with such a request.
In truth, you will need to pass evidence parameters, at best, in the form of implicit parameters.
The best I can think of is on the line
class PayLoad trait LowPriMaybeCarry { implicit def no[C] = new NoCarry[C] } object MaybeCarry extends LowPriMaybeCarry { implicit def canCarry[C <: PayLoad](c: C) = new Carry[C] } sealed trait MaybeCarry[C] final class NoCarry[C] extends MaybeCarry[C] final class Carry[C <: PayLoad] extends MaybeCarry[C] { type C <: PayLoad } class SomeClass[C <: PayLoad] def test[C]( implicit mc: MaybeCarry[C]) : Option[SomeClass[_]] = mc match { case c: Carry[_] => Some(new SomeClass[ cC ]) case _ => None }
but still i can't get implicits to work:
test[String] test[PayLoad] // ouch, not doin it test[PayLoad](new Carry[PayLoad]) // sucks
So, if you want to keep serous brain damage, I would forget about the project or look for another language. Is Haskell better here? I still hope that we can eventually match the types, but my hopes are pretty low.
Perhaps the guys from scalaz came up with a solution, they pretty much used the Scala type system to the limits.
source share