Advertisement
Guest User

Untitled

a guest
May 29th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import reflect.runtime.universe._
  2.  
  3. trait AST[T] {
  4. def tpe: Type
  5. }
  6.  
  7. case class ASTVal[T: WeakTypeTag](value: T) extends AST[T] {
  8. def tpe = implicitly[WeakTypeTag[T]].tpe
  9. }
  10.  
  11. abstract class ASTTypeMatch[T: WeakTypeTag] {
  12. def unapply(v: AST[_]) = v.tpe =:= implicitly[WeakTypeTag[T]].tpe
  13. }
  14.  
  15. object isLong extends ASTTypeMatch[Long]
  16. object isDouble extends ASTTypeMatch[Double]
  17. // etc ...
  18.  
  19. object Test {
  20. def test[T](ast: AST[T]) = ast match {
  21. case a @ isLong() => //do something with a: AST[Long]
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement