Skip to content

Instantly share code, notes, and snippets.

@4e6
Last active November 12, 2015 14:19
Show Gist options
  • Save 4e6/ad1b70a22d769f0edaa9 to your computer and use it in GitHub Desktop.
Save 4e6/ad1b70a22d769f0edaa9 to your computer and use it in GitHub Desktop.
// 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