Open
Description
Compiler version
3.0
Minimized code
sealed trait Ty {
type T
}
case object TUnit extends Ty {
type T = Unit
}
final case class TFun(dom: Ty, cod: Ty) extends Ty {
type T = dom.T => cod.T
}
def default(ty: Ty): ty.T = ty match {
case TUnit => ()
case TFun(dom, cod) => { (x: dom.T) => default(cod) }
}
Output
Found: Unit
Required: ty.T
Found: dom.T => cod.T
Required: ty.T
Expectation
I expected the result type inside of the match to be specialized to Unit
for TUnit
and dom.T => cod.T
for TFun
, but this is not the case. It may be the case that I expect too much though.
With GADTs the result types are specialized, but I cannot type the x
in the case of TFun
, because I have no access to the type parameters of TFun
:
sealed trait Ty[T]
case object TUnit extends Ty[Unit]
final case class TFun[A, B](dom: Ty[A], cod: Ty[B]) extends Ty[A => B]
def default[T](ty: Ty[T]): T = ty match {
case TUnit => ()
case TFun(dom, cod) => { x => default(cod) }
/*
Missing parameter type
I could not infer the type of the parameter x.
*/
}