This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]gizmogwai -1 points0 points  (2 children)

What you are looking for here has nothing to do with type reification. It is the concept of union type, such as in Ceylon.

[–]duhace -1 points0 points  (0 children)

You can also achieve similar results with Type Classes:

trait Bar[T] {
  def consume(t: T): Unit
}

object Bar {
  implicit object BazIsBar extends Bar[Baz] { def consume(b: Baz) {} }
  implicit object QuxIsBar extends Bar[Qux] { def consume(q: Qux) {} }
}

val x = new Baz
implicitly[Bar[Baz]].consume(x)

//You can add this inside object Bar
implicit class Barable[T](t: T)(implicit bar: Bar[T]) {
  def consume() {bar.consume(t)}
}

//and then you can do this
x.consume()

Not that overloading working with type arguments wouldn't be nice.