-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft for compound extension types and variations
- Loading branch information
1 parent
720dbea
commit 9f23575
Showing
4 changed files
with
185 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,95 @@ | ||
# User-Defined Types | ||
|
||
User Defined Types can be created using a combination of pre-defined simple and compound types. User-defined types are defined as part of [simple extensions](../extensions/index.md#simple-extensions). An extension can declare an arbitrary number of user defined extension types. Initially, user defined types must be simple types (although they can be constructed of a number of inner compound and simple types). | ||
User Defined Types can be created using a combination of pre-defined simple and compound types. User-defined types are defined as part of [simple extensions](../extensions/index.md#simple-extensions). An extension can declare an arbitrary number of user defined extension types. Once a type has been declared, it can be used in function declarations. | ||
|
||
A YAML example of an extension type is below: | ||
## Structure | ||
|
||
User defined types may be opaque, or may be specified as a structure of preexisting types. A simple example of the latter is: | ||
|
||
```yaml | ||
name: point | ||
structure: | ||
longitude: i32 | ||
latitude: i32 | ||
``` | ||
This declares a new type (namespaced to the associated YAML file) called "point". This type is composed of two `i32` values named longitude and latitude. | ||
|
||
[TBD: should field references be allowed to dereference the components of a user defined type?] | ||
|
||
## Parameterization | ||
|
||
User-defined types may be parameterized, in the same way in which the built-in compound types are parameterizable. The supported "meta-types" for parameters are data types, booleans, integers, enumerations, and strings. Using parameters, we could redefine "point" with different types of coordinates. For example: | ||
|
||
```yaml | ||
name: point | ||
parameters: | ||
- name: T | ||
description: | | ||
The type used for the longitude and latitude | ||
components of the point. | ||
type: type | ||
``` | ||
|
||
or: | ||
|
||
```yaml | ||
name: point | ||
parameters: | ||
- name: coordinate_type | ||
type: enum | ||
options: | ||
- integer | ||
- double | ||
``` | ||
|
||
or: | ||
|
||
```yaml | ||
name: point | ||
parameters: | ||
- name: LONG | ||
type: type | ||
- name: LAT | ||
type: type | ||
``` | ||
|
||
We can't specify the internal structure in this case, because there is currently no support for derived types in the structure. | ||
|
||
The allowed range can be limited for integer parameters. For example: | ||
|
||
```yaml | ||
name: vector | ||
parameters: | ||
- name: T | ||
type: type | ||
- name: dimensions | ||
type: integer | ||
min: 2 | ||
max: 3 | ||
``` | ||
|
||
This specifies a vector that can be either 2- or 3-dimensional. | ||
|
||
Similar to function arguments, the last parameter may be specified to be variadic, allowing it to be specified one or more times instead of only once. For example: | ||
|
||
```yaml | ||
name: union | ||
parameters: | ||
- name: T | ||
type: type | ||
variadic: true | ||
``` | ||
|
||
This defines a type that can be parameterized with one or more other data types, for example `union<i32, i64>` but also `union<bool>`. Zero or more is also possible, by making the last argument optional: | ||
|
||
```yaml | ||
name: point | ||
structure: | ||
longitude: i32 | ||
latitude: i32 | ||
name: tuple | ||
parameters: | ||
- name: T | ||
type: type | ||
optional: true | ||
variadic: true | ||
``` | ||
|
||
This declares a new type (namespaced to the associated YAML file) called "point". This type is composed of two `i32` values named longitude and latitude. Once a type has been declared, it can be used in function declarations. [TBD: should field references be allowed to dereference the components of a user defined type?] | ||
This would also allow for `tuple<>`, to define a zero-tuple. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters