You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the below code, pattern matching silently upcasts invariant type Exp, from Exp[Double] to Exp[Any] even though Exp is invariant.
caseclassMan[T]()
implicitdefman[T] =Man[T]()
abstractclassExp[T:Man] {
defmT= man[T]
}
caseclassConst[A:Man](x: A) extendsExp[A]
caseclassNode[A:Man, B:Man](base: Exp[A]) extendsExp[B] {
defmA= man[A]
defmB= man[B]
}
valm=Node[Int, String](Node[Double, Int](Const(3.14)))
valn= m match {
caseNode(Node(t)) => t
}
//At the REPL we get//n: Exp[Any] = Const(3.14)//scala> n.mT//res0: Man[Any] = Man()
This example was shown to me by my colleague Cai Yufei; the above typing issue occurs when trying to write a type-correct map fusion in LMS-like scenarios - this explains the strange type for Node above.
The use of primitive types above is irrelevant, as shown below:
scala>valm=Node[java.io.File, StringBuffer](Node[String, java.io.File](Const("a string")))
m:Node[java.io.File,java.lang.StringBuffer] =Node(Node(Const(a string)))
scala>valn= m match {
|caseNode(Node(t)) => t
| }
n:Exp[Any] =Const(a string)
The text was updated successfully, but these errors were encountered:
In the below code, pattern matching silently upcasts invariant type Exp, from Exp[Double] to Exp[Any] even though Exp is invariant.
This example was shown to me by my colleague Cai Yufei; the above typing issue occurs when trying to write a type-correct map fusion in LMS-like scenarios - this explains the strange type for
Node
above.The use of primitive types above is irrelevant, as shown below:
The text was updated successfully, but these errors were encountered: