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
This is a tracking issue for the implementation of complex types and layouts. Here is the current state of implementation. Below are the specification for each feature:
Union/sum types & layouts
Intersection types & layouts
Literal types
Enumeration layouts
Restrictions
Predicate constraints
Priority goes to the implementation of literal types (without regular expression) and union types.
Union/sum types & layouts
A sum type (or union type) is defined as the union of a set of types. A value is an instance of this type if it is an instance of at least one type of the set. It is defined using the | operator.
type Sum = A | B | C
The layout of this type is an union layout, following a similar syntax (although it does not need to be explicitly defined):
layout SumLayout = ALayout | BLayout | CLayout
Such layout is translated into an enumeration in the target language. Here in Rust:
enumSumLayout{A(ALayout),B(BLayout),C(CLayout)}
If possible, the definition can be inlined in the target language, here in TypeScript:
typeSumLayout=ALayout|BLayout|CLayout
Intersection types & layouts
Similarly, an intersection type is the intersection of a set of types, defined with the & operator.
type Inter = A & B
The layout of this type is a structure defining fields that correspond a property of any of the field in the intersection. The structure must define fields for the required property of all the type in the intersection.
The implementation may be delayed for a future PR since it is not required now.
Literal types & layouts
Literal types define a subset of all literal values using either a string, or a regular expression (using at least POSIX Basic Regular Expressions for now). For instance, the following type defines
the property constant whose value must be equal to "foo".
type Foo {
constant: "foo"
}
Regular expression types
Literal types are a particular case for regular expression types,
where each instance of the type matches the defining regular expression.
The following type defines the regexp property whose value must
match the /foo+/ regular expression recognizing every "fo...o" string with at least two o.
type Foo {
regexp: /foo+/
}
Enumeration layouts
An enumeration layout is defined as list of variants declared between [ ].
layout Enum [A, B]
Such layout will be translated into an enumeration type in the target language.
Each variant can have a payload, defined as a structure layout (between { }). Variants must not be ambiguous: there must be a way of telling variants apart just by looking at the payload, and not at the name of the variant. If a variant has no payload, it must be assigned a singleton value using the =.
For instance, the following layout can be defined for the rdf:list type:
layout List for rdf:type [
Nil = rdf:nil,
Cons {
rdf:first: Any,
rdf:rest: List
}
]
Restrictions
Intersection type can also be defined using restrictions defined
using the where keyword.
For instance the following type defines the subtype of wine located in the Bourgogne Region of France:
type Burgrundy = Wine where locatedIn: "bourgogne"
Predicates constraints
Type constraints using predicates, such as numerical constraints:
type Age = { x: xsd:integer, x >= 0 && x < 130 }`
Syntax is not fixed yet.
The text was updated successfully, but these errors were encountered:
This is a tracking issue for the implementation of complex types and layouts. Here is the current state of implementation. Below are the specification for each feature:
Priority goes to the implementation of literal types (without regular expression) and union types.
Union/sum types & layouts
A sum type (or union type) is defined as the union of a set of types. A value is an instance of this type if it is an instance of at least one type of the set. It is defined using the
|
operator.The layout of this type is an union layout, following a similar syntax (although it does not need to be explicitly defined):
Such layout is translated into an enumeration in the target language. Here in Rust:
If possible, the definition can be inlined in the target language, here in TypeScript:
Intersection types & layouts
Similarly, an intersection type is the intersection of a set of types, defined with the
&
operator.The layout of this type is a structure defining fields that correspond a property of any of the field in the intersection. The structure must define fields for the required property of all the type in the intersection.
The implementation may be delayed for a future PR since it is not required now.
Literal types & layouts
Literal types define a subset of all literal values using either a string, or a regular expression (using at least POSIX Basic Regular Expressions for now). For instance, the following type defines
the property
constant
whose value must be equal to"foo"
.Regular expression types
Literal types are a particular case for regular expression types,
where each instance of the type matches the defining regular expression.
The following type defines the
regexp
property whose value mustmatch the
/foo+/
regular expression recognizing every"fo...o"
string with at least twoo
.Enumeration layouts
An enumeration layout is defined as list of variants declared between
[ ]
.Such layout will be translated into an enumeration type in the target language.
Each variant can have a payload, defined as a structure layout (between
{ }
). Variants must not be ambiguous: there must be a way of telling variants apart just by looking at the payload, and not at the name of the variant. If a variant has no payload, it must be assigned a singleton value using the=
.For instance, the following layout can be defined for the
rdf:list
type:Restrictions
Intersection type can also be defined using restrictions defined
using the
where
keyword.For instance the following type defines the subtype of wine located in the Bourgogne Region of France:
Predicates constraints
Type constraints using predicates, such as numerical constraints:
Syntax is not fixed yet.
The text was updated successfully, but these errors were encountered: