-
Notifications
You must be signed in to change notification settings - Fork 0
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
Value Types #265
Comments
Fields with a primitive datatype or enum type are required and cannot be Rationale: Simplification, adhere to "small composite of values" idea. |
For fields of enum type, we store the enum literal's key (#128). This key might be specific to a version of the hosting language. We always know this version, because it is mentioned in the definition of the structured datatype. |
We do not reuse M3 Rationale: |
We could introduce value types in LionWeb.
Characteristics
Value types:
Support in programming languages
readonly struct
class
with different default visibility)Proposal for LionWeb: Value types as structured datatypes
A language can define a structured datatype (name tbd). Its a specialization of
Datatype
, thus can be used as type of a Property.A structured datatype consists of one or more fields (name tbd). Each field has a
name
,key
(inherited fromIKeyed
), andtype
.type
is a reference to aDatatype
. In other words: A structured datatype is a named tuple of other datatypes.It can NOT contain
Classifier
s.Rationale: we have a strict separation between identified things (nodes) and values. If we allowed nodes inside structured datatypes, we can have nodes nested inside the value-world of properties.
Structured datatypes can NOT inherit from anything, and can NOT implement interfaces.
Rationale: inheritance seems widely not supported by programming languages. It also clashes with the idea of "small composite of values". Technically I don't see a reason why we should not allow inheritance (besides programming language support).
All listed programming languages allow interface implementation, but for behavior only. We don't have behavior at all in LionWeb, thus allowing to implement interfaces makes no sense. Also, interfaces might have
Link
features which are not allowed in a structured datatype.We could support value interfaces like Kotlin if we wanted to group similar structured datatypes. This seems again at odds with the "small composite of values" idea -- if we have to group them, they aren't that small any more.
Structured datatypes CAN have a field with themselves as type.
Rationale: With value semantics, and no possibility to reference structured datatypes, I don't see an issue with nesting.
We cannot pre-calculate their size, but neither can we for
String
values.All fields are required.
Rationale: Simplification, adhere to "small composite of values" idea.
I don't think we have to make a statement about mutability, other than NOT supporting delta updates of parts of a structured datatype
Property
.Rationale: LionWeb is a protocol, and thus at its core only care about data in transit. During one transit, no data changes ever.
Assume we have a
Structured Datatype Color { red: Integer , green: Integer, blue: Integer }
and aConcept Apple { property color: Color }
. Assume we writemyApple.color.red = 255
in our client's code, implemented in some programming language.Whether the programming language changes the existing
Color
value, or creates a new copy of the previous value with updatedred
component, is not relevant to LionWeb.We could state the assumption that structured datatypes are immutable to encourage more uniform implementations, and enable optimizations (e.g. de-duplication).
We serialize structured datatype instances as strings, the same as any other
Datatype
. the string contains a JSON structure corresponding to the structured datatype, using the fieldkey
as JSON member key, and the instance's field value as JSON member value. We omit the string escaping for nested structured datatypes.Rationale: We already support JSON datatypes.
Using a field's
key
instead of itsname
is in line with the rest of serialization, and avoids issues with renaming.We don't want to add one level of string escaping for every nesting of structured datatypes, as this would be very error-prone to parse and extremely tedious to read or write by a human.
Example 1: Apple with color
M2:
M1:
Example 2: Complex number with Decimal
M2:
M1:
(note: the newlines inside
key-sqrtres-result
value serve readability, they would be omitted.)Questions
Property
? Can we re-useProperty
there? The only difference is the required flag of Properties (would always betrue
for fields).The text was updated successfully, but these errors were encountered: