-
Notifications
You must be signed in to change notification settings - Fork 43
Unitful literals #3688
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
base: master
Are you sure you want to change the base?
Unitful literals #3688
Conversation
The ease of use and readability provided by this proposal is important for the acceptance of this as a correct way to address the unit error in a situation like this:
This PR makes no changes to unit checking; the following should be rejected as inconsistent:
|
The latter isn't even close to beginning to meaningfully adress the actual problems this would introduce in practice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid merging by mistake:
As repeatedly indicated this makes it easy to introduce non-coherent units, which requires a detailed analysis.
It is hard to think of a programming language where units and unit checking matter more than in Modelica. It is just silly that the language is lacking this basic construct of constructing unitful literals. Applications are everywhere:
Example of the day:
Due to the lack of clarity and the wildcard effect, the error above is easy to make, and the model developer who knows that the model only works for acute angles might fail to check that the assertion actually works. If the developer would have used a unitful literal instead, a unit inconsistency would have revealed the problem:
When corrected, the attached unit adds clarity and removes any uncertainty related to the wildcard effect:
If the modeler decides to use |
Let's not pretend that we can't perform a decent amount of unit checking, and let's not assume that the feature would be massively misused to exploit any gaps we still have in the unit checking semantics. The alternative, using numeric literals without unit and relying on the wildcard effect is so much worse than the tiny risk of introducing a unitful literal with non-coherent unit in a place where it wouldn't be caught by unit checking. |
The original design was to have equations in coherent units; and have non-coherent units in the user interface at the boundary. Apart from that the previously raised issues with temperatures, and rotations are still unresolved. |
I think we need external input to make progress here. @casella, @AHaumer, @GallLeo, @hubertus65, would you be interested in joining us for a session about the pros and cons of being able to express unitful literals in expressions and equations? |
I don't see it as meaningful to involve more people when there are still no answers regarding how possibly non-coherent units in equations would actually work, especially for temperatures and rotations. |
It's also misleading to tell others that the issue is 'unitful literals' when the problem is that it's suddenly easy to add possibly non-coherent units like I have still not seen anything meaningful addressing those issues, or how it would work in practice. Just to be clear: the proposal isn't to allow |
This is the design for attaching units to literals that was discussed at the most language design meeting in Linköping held in March this year. The proposal is an alternative to #3668, with emphasis on simple design, ease of use, and human readability.
This design was originally implemented in SimulationX, and later given two parallel implementations in System Modeler - one for testing it in regular Modelica expressions, and one for (undocumented) use in vendor-specific annotations.