-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type check for polymorphic function types #13918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I updated the post, but I think I've reduced it to: class Base[X] {type Carrier = X}
class Cond[V] {type Match}
trait TA[X]
trait TB[X]
trait TAdvancedA[X] extends TA[X]
trait TAdvancedB[X] extends TB[X]
trait T1[X] extends Base[X] with TA[X]
trait T2[X] extends Base[X] with TA[X] with TAdvancedB[X]
def insT1[A] = new T1[Set[A]] {}
def insT2[A] = new T2[(Set[A], Set[A])] {}
val condAB = [V] => () => new Cond[V] {type Match = TA[V] & TB[V]}
@main def example =
def app[X, Y](x: X, f: X => Y) = f(x)
for ins <- Seq(insT1[String], insT2[Int]) do
// this works correctly
println(app(condAB[ins.Carrier](), v => ins.isInstanceOf[v.Match]))
// this does not compile
// println(app(condAB, c => {val v = c[ins.Carrier](); ins.isInstanceOf[v.Match]})) |
It's known that polymorphic function types don't play well with type inference, and usually have to be instantiated explicitly. |
What does it mean to be instantiated explicitely here? |
you will need to supply the types to for ins <- Seq(insT1[String], insT2[Int]) do
println(app[condAB.type, Boolean](condAB, c => {val v = c[ins.Carrier](); ins.isInstanceOf[v.Match]})) |
Hmm that only works in the case of hard coded conditions right @bishabosha? val inss = Seq(insT1[String], insT2[Int])
val conds = Seq(condAB, condQA)
for ins <- inss; cond <- conds do
val v = cond[ins.Carrier]()
println(ins.isInstanceOf[v.Match]) I can't use condAB.type (and this fails with val conds = Seq[[V] => () => TestGroup[V]](condAB, condQA) gives the wrong result. |
What you are doing in this example relies on static types to work, so I can only to suggest that you zip each |
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.1.2-RC1-bin-20211102-82172ed-NIGHTLY
Minimized code
I've found it really hard to minimize this due too all the moving components.
You can click the little triangle to see the full attempt.
Here are the bits where I think it goes wrong:
Output
Expectation
Work the same as
Two things here:
([V] => () => TestGroup[V]{R = IP.lib.UpperBound[V] & PartialOrdering[V]})
to match type([V] => () => TestGroup[Any]{R = IP.lib.UpperBound[Any] & PartialOrdering[Any]})
?(λx.G) (f v)
to be equivalent to(λx.G[x := (f x)]) v
.The text was updated successfully, but these errors were encountered: