I’d like to associate two types with each other, so that when I have some type
In, I can call a method or a macro and get out some object of type Out, where
Out type depends on
def transformType[In]: Out = ???
I can get something very similar easily with implicits only and it works fine, so the compiler generally knows how to do what I want, assuming the association is unique by only one available instance of the implicit:
def transform[In, Out](in: In)(implicit obj: Transform[In, Out]): Out = ??? implicit object IntTransform extends Transform[Int, String] val out = transform(1) // out is a String, and the compiler figured it out by itself, awesome!
Unfortunately this has one minor downside - it requires an instance of type In.
Given availability of an implicit associating types In and Out, is it possible to get type Out from type In, inside a macro?
Is it possible to make a method / macro computing such dependent type (dependent on another type, not value)?
val out = transformType[Int] // out is some default instance of String