Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. sealed trait Key[A] { type Inner = A }
  2. trait IntKey extends Key[Int]
  3. trait StringKey extends Key[String]
  4.  
  5. // This should compile
  6. object Key {
  7. def work[A](m: Key[A]): m.Inner = m match {
  8. case i: IntKey => 1
  9. case s: StringKey => "1"
  10. }
  11. }
  12. // scala> Key work new IntKey{}
  13. // res0: Int = 1
  14.  
  15. // scala> Key work new StringKey{}
  16. // res1: String = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement