Last active
November 12, 2015 14:19
-
-
Save 4e6/ad1b70a22d769f0edaa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JsValue remembers Adapter | |
trait JsValue { | |
type A | |
} | |
object JsValue { | |
type Aux[A0] = JsValue { type A = A0} | |
} | |
// Adapter works with JsValue of type T | |
class Adapter[T] { self => | |
def get: JsValue.Aux[T] = | |
new JsValue { | |
type A = T | |
} | |
def set(v: JsValue.Aux[T]) = () | |
} | |
class A | |
class B | |
object AdapterTest { | |
val a1, a2 = new Adapter[A] | |
val b1 = new Adapter[B] | |
val js1 = a1.get | |
val js2 = a2.get | |
a1.set(js1) // compiles | |
a1.set(js2) // compiles | |
b1.set(js1) // do not compiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment