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
The idea of this ticket is to make "incompatible dimensions" errors better. Take this example:
>>> kg m / s^2 + kg m^2
error: while type checking
┌─ <input>:1:1
│
1 │ kg m / s^2 + kg m^2
│ ^^^^^^^^^^ - ^^^^^^ Length² × Mass
│ │ │
│ │ incompatible dimensions in addition
│ Length × Mass × Time⁻²
│
= left hand side: Length × Mass × Time⁻²
right hand side: Length² × Mass
There are several things that could be improved here.
Definitely included in this ticket:
In the upper part of the error message (and probably everywhere else where we print out types), format types like Length × Time⁻¹ as Length / Time, which is much easier to read. This can be done in analogy to what we do for pretty-printing units already.
In the lower part of the error message, line up the dimensions for easy comparison, i.e. sort them, add "¹" in places with no exponent, and add ⁰ for missing dimensions on either side:
= left hand side: Length¹ × Mass × Time⁻²
right hand side: Length² × Mass × Time⁰
(debatable whether or not we want a ¹ exponent for the Mass part)
In addition, show known dimension names, i.e. Speed for Length / Time. This can probably be done with a dictionary lookup over existing dimensions:
= left hand side: Length¹ × Mass × Time⁻² (Force)
right hand side: Length² × Mass × Time⁰ (MomentOfInertia)
(MomentOfInertia is currently not defined, but we should add a few more dimensions in dimensions.nbt anyway). We would not do that for base dimensions like Length (i.e. whenever we would not add additional information). But we would show Area for Length².
Show suggestions on what to do. We can probably go crazy here but let's start with something simple: we could compute missing_type = type(lhs)/type(rhs) and add a suggestion to multiply the right-hand-side by missing_type. We would probably only do this, if missing_type is "not too complicated". And if missing_type contains "a lot of negative exponents", we could compute the inverse instead (type(rhs)/type(lhs)), and suggest to multiply the left-hand-side by the result. Or maybe it's better to always show both alternatives. For the example above, we could show something like: "Suggestion: multiply the left-hand-side by Time² × Length".
Stretch goals:
See if it's possible/sensible to avoid the code duplication between pretty-printing dimension expressions and "unit expressions". For example: the logic for formatting the unit meter × second⁻¹ as m/s and the logic for formatting the type Length × Time⁻¹ as Length / Time is exactly the same.
Colorize the "diff" in the types, e.g. highlight the Length and Time factors in the example above in red, and the Mass factor in green.
Think of more sophisticated heuristics for providing even better suggestions.
The text was updated successfully, but these errors were encountered:
This changeset enhances "incompatible dimensions" errors by aligning
them for better readability, adding additional information and providing
suggestions on how to fix them.
closes#104
The idea of this ticket is to make "incompatible dimensions" errors better. Take this example:
There are several things that could be improved here.
Definitely included in this ticket:
Length × Time⁻¹
asLength / Time
, which is much easier to read. This can be done in analogy to what we do for pretty-printing units already.Mass
part)Speed
forLength / Time
. This can probably be done with a dictionary lookup over existing dimensions:MomentOfInertia
is currently not defined, but we should add a few more dimensions indimensions.nbt
anyway). We would not do that for base dimensions likeLength
(i.e. whenever we would not add additional information). But we would showArea
forLength²
.missing_type = type(lhs)/type(rhs)
and add a suggestion to multiply the right-hand-side bymissing_type
. We would probably only do this, ifmissing_type
is "not too complicated". And ifmissing_type
contains "a lot of negative exponents", we could compute the inverse instead (type(rhs)/type(lhs)
), and suggest to multiply the left-hand-side by the result. Or maybe it's better to always show both alternatives. For the example above, we could show something like: "Suggestion: multiply the left-hand-side by Time² × Length".Stretch goals:
meter × second⁻¹
asm/s
and the logic for formatting the typeLength × Time⁻¹
asLength / Time
is exactly the same.Length
andTime
factors in the example above in red, and theMass
factor in green.The text was updated successfully, but these errors were encountered: