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
We try to avoid showing constraint-solver error messages wherever we can, because they will probably always be worse than direct type-checker errors. Unfortunately, there are still some cases where they show up. A simplified example looks like this:
>>> fn id(x) = x
fn id<A>(x: A) -> A = x
>>> 1 meter + id(1 second)
error: Could not solve the following constraints:
Length / Time = Scalar
.. while trying to infer types in the (elaborated) statement:
1 metre + id(1 second)
= Consider adding type annotations to get more precise error messages.
Here, we instantiate id :: T0 -> T0 with a fresh type variable T0, add a Time ~ T0 constraint for the argument, and a Length ~ T0 constraint for the return type. But we fail to stop immediately and instead go into the constraint solver stage where those two constraints are turned into a single Length ~ Time and subsequently into a Length / Time = Scalar dtype constraint, which can not be solved.
The text was updated successfully, but these errors were encountered:
So in the provided example, the goal is to be able to go back and attach the constraint solver error to the + (which must have two arguments of the same type)? Or more concretely, to develop heuristics about which generic parameter unifications should have highest precedence? i.e., that f<A>(x: A) -> A should be solved earlier in the constraint solving process than add<A>(x: A, y: A) -> A because it is “more deterministic” — although I'm having trouble articulating exactly how (bottom up vs. top down?). It seems like one simple heuristic (that needs verification) is that unifying an input generic parameter with an output generic parameter should take higher precedence than unifying two input generic parameters. Perhaps also that constraints should be solved in the order that the expressions would be evaluated (the latest expression to be evaluated should have its constraints’ failures be the ones reported).
We try to avoid showing constraint-solver error messages wherever we can, because they will probably always be worse than direct type-checker errors. Unfortunately, there are still some cases where they show up. A simplified example looks like this:
Here, we instantiate
id :: T0 -> T0
with a fresh type variableT0
, add aTime ~ T0
constraint for the argument, and aLength ~ T0
constraint for the return type. But we fail to stop immediately and instead go into the constraint solver stage where those two constraints are turned into a singleLength ~ Time
and subsequently into aLength / Time = Scalar
dtype constraint, which can not be solved.The text was updated successfully, but these errors were encountered: