Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import reflect.runtime.universe._
- trait AST[T] {
- def tpe: Type
- }
- case class ASTVal[T: WeakTypeTag](value: T) extends AST[T] {
- def tpe = implicitly[WeakTypeTag[T]].tpe
- }
- abstract class ASTTypeMatch[T: WeakTypeTag] {
- def unapply(v: AST[_]) = v.tpe =:= implicitly[WeakTypeTag[T]].tpe
- }
- object isLong extends ASTTypeMatch[Long]
- object isDouble extends ASTTypeMatch[Double]
- // etc ...
- object Test {
- def test[T](ast: AST[T]) = ast match {
- case a @ isLong() => //do something with a: AST[Long]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement