Skip to content

Instantly share code, notes, and snippets.

@emilypi
Created February 7, 2017 19:33
Show Gist options
  • Select an option

  • Save emilypi/c265df205e60fca567d9791b6086f62f to your computer and use it in GitHub Desktop.

Select an option

Save emilypi/c265df205e60fca567d9791b6086f62f to your computer and use it in GitHub Desktop.
Generating fully qualified class instance from Tagged Union types with an associated Generator
trait Instantiator[+A] {
def apply(): A
}
object Instantiator {
def apply[A](create: => A): Instantiator[A] = new Instantiator[A] {
def apply(): A = create
}
}
class U
object U {
implicit val instantiator: Instantiator[U] = Instantiator { new U }
}
class T
type Tagged[U] = { type Tag = U }
type @@[T, U] = T with Tagged[U]
def gen[V: Instantiator]: V = implicitly[Instantiator[V]].apply()
gen[(T @@ U)#Tag]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment