-
Notifications
You must be signed in to change notification settings - Fork 27
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
Inferencer fails to figure out ! on typevars #29
Comments
So, it's worth noting that given a constraint:
we can't solve One thing we might want to do is to emit a better error message for this scenario than "leftover constraint". We might want to examine what the leftover constraint is and give a more helpful error message in some other scenarios too. But I'm pretty much taking the position that this isn't a bug, but rather just an incompleteness of the inference algorithm that can be worked around. |
Agreed. That's why I didn't tag it a bug. Some heuristics can be used to solve some obvious cases, but I'd leave it as future work. |
Better error messages (and in general) is much appreciated, otherwise it will force me to be around when someone is using the language :P |
Alternatively an easier workaround would be to have some type holes syntax, so that users can help the compiler know the instantiation of the outstanding typevars, without having to annotate all type args. |
That would be nice to have. Right now you can partially apply type args, but you can't apply later args without applying earlier args first. I think a better workaround is to use the kind system though. That's what it's there for. |
What about things like |
That |
I got
|
With/out the |
This is another one of those situations where we could solve that I'm thinking that we should solve them whenever we can... I just need to isolate the cases where it's possible clearly. |
I guess it's always possible to |
If it's |
With what we have now, typeargs are not in a situation that's much better than what we had before. Selectively removing/adding them is brain intensive. Doing a bit more keystrokes saves brains. |
Hm, so the only problem with our guessing strategy is that we can't tell whether any r sigils exist without fully expanding all type synonyms, and currently (for error message reasons) the solver only simplifies to WHNF. |
Do we have to know what |
That would just end up with the same constraints but for the new unif. var. One option would be to solve them up to WHNF, e.g if you have:
then we generate fresh
But I'd have to add rules for every single type modulo |
Some real examples: in
|
This should be somewhat mitigated by Amos and my changes to type inference in Sink/Float. |
Synopsis
The Problem
In a nutshell, if there's a function whose type includes a
forall
quantified type variablea
(for example) anda!
appears in the type signature, then it's very likely you'll encounter a constraint of the form(?0)! :< T
which is unsolvable by the constraint solver and you'll get a typecheck error of leftover constraints.The Solution
If possible, avoid this form of type signature. Instead, use explicit constraints, like
forall (a :< DS). ...
. There're cases where it is impossible to do so. In that case, you have to explicitly do the type application likef [U8, Bool, A]
yourself. Note that partial type application is allowed, and holes are supported so you can only apply the type that is in question. E.g.f [_, Bool]
.Also see discussion in #22 and 255f000
The text was updated successfully, but these errors were encountered: