Type-safe assignments and valuations #76
mtf90
started this conversation in
AutomataLib Discussions
Replies: 1 comment 2 replies
-
This is ok for me. Can you prepare a pull request with a proposal? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
During my work on cleaning up type definitions (cf. #75) I found that many assignments lack proper type checking. In fact, you can easily assign a
String
value to anInteger
register or parameter. While one could add additional type-equality checks, these would only detect errors at runtime. I was wondering whether it is desirable to have compile-time type checking as well? Essentially, this would makeSymbolicDataValue
s (incl. sub-classes) parameterized in theirDataType<T>
.This would not get rid of runtime checks completely because you can always create types such as
DataType<Integer>("id", Integer.class)
andDataType<Integer>("pin", Integer.class)
which are type-compatible but unequal. However, it would at least allow for more type specificity, because users could decide to create explicitId
andPin
classes for this purpose.Furthermore, the current assignment structure would have to change. You cannot enforce (nested) type constraints on keys and values if, e.g., a
VarMapping
is aMap<SymbolicDataValue<?>, SymbolicDataValue<?>>
(otherwise you would not allow assignments of different-typed registers). So rather than aMap<X, Y>
the assignments would need to be encoded as aCollection<Assignment<?>>
whereAssignment<T>
enforces the same typeT
on the target and the source (there would be specific sub-classes for registers, parameters, valuations, etc.).Currently, this isn't that much of a problem, because in most cases guards, etc. only check for equality which works on arbitrary
Object
s. However, already theAtomicGuardExpression
could be cleaned up if theSMALLER
/BIGGER
guards could enforce a<T extends Comparable<T>>
bound. Especially looking forward to more complex guards (cf. #73 (comment)), proper typing support could be very beneficial.I'm in favor of this refactoring because I like to utilize the strong typing capabilities of the language. The compiler is a friend that helps you to prevent errors. However, since this would induce quite a lot of refactoring, I'd like to hear other opinions first. Especially if you have other solutions to this problem, feel free to present/discuss them here.
Beta Was this translation helpful? Give feedback.
All reactions