Consider this code:
trait TypeOr[E, F] {
type T
}
implicit def noneq2[E, F](implicit ev: E =!= F): TypeOr[E, F] = new TypeOr[E, F] {
type T = (E, F)
}
sealed trait Error[+E, +A]
case class Err[E, A](e: Error[E, A]) {
def combine[B, F](f: A => Error[F, B])(implicit ev: TypeOr[E, F]): Error[ev.T, B] = ???
}
val result = Err(null.asInstanceOf[Error[Int, Int]]).combine(_ => null.asInstanceOf[Error[String, String]])
So far so good. From the definitions above, I concluded, that the expanded type of the result is following:
val itsType: Error[(Int, String), String] = result
But apparently it is not, since the compiler replies with:
found : returnerror.Comb.Error[returnerror.Comb.TypeOr[Int,String]#T,String]
required: returnerror.Comb.Error[(Int, String),String]
val itsType: Error[(Int, String), String] = result
Is it possible to find out the simplified - expanded type of the expression? I can't get this information from compiler, I tried to print the AST before the erasure phase, but the expanded type is still not there.
returnerror.TypeOr
? – EjectorTypeOr
andTuple2
are equivalent. Should they be? – ForgivingscalacOptions in Compile ++= Seq("-Xprint-types", "-Xprint:typer")
to build.sbt. – Strubleimport scala.reflect.runtime.universe._
def printType[A: TypeTag](a: A) = println(typeOf[A])
– Strubleprintln(typeOf[A].dealias)
. – Struble