-
Notifications
You must be signed in to change notification settings - Fork 76
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
Improve Terminology? - nullable primitive type #203
base: main
Are you sure you want to change the base?
Changes from 8 commits
32dbf5f
5aae8fa
a4149bb
e8175a2
0e71cc1
a479ed4
68a912d
7d5d05f
da75a6b
4e9de2f
28ccf8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,24 +26,26 @@ A _type value_ is a value that _classifies_ other values. A value that is classi | |
|
||
The set of _primitive types_ includes the types of primitive values, and a number of _abstract types_, which are types that do not uniquely classify any values: `function`, `table`, `any`, `anynonnull` and `none`. All function values conform to the abstract type `function`, all table values to the abstract type `table`, all values to the abstract type `any`, all non-null values to the abstract type `anynonnull`, and no values to the abstract type `none`. An expression of type `none` must raise an error or fail to terminate since no value could be produced that conforms to type `none`. Note that the primitive types `function` and `table` are abstract because no function or table is directly of those types, respectively. The primitive types `record` and `list` are non-abstract because they represent an open record with no defined fields and a list of type any, respectively. | ||
|
||
All types that are not members of the closed set of primitive types plus their nullable counterparts are collectively referred to as _custom types_. Custom types can be written using a `type-expression`: | ||
The set of _primitive types_ plus their nullable counterparts are known as the _primitive-or-nullable-primitive-types_ or alternately as the _non-custom types_. | ||
bgribaudo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_primitive-type:_ one of<br/> | ||
`any anynonnull binary date datetime datetimezone duration function list logical`<br/> | ||
`none null number record table text time type`<br/> | ||
_primitive-or-nullable-primitive-type:_<br/> | ||
`nullable`_<sub>opt</sub> primitive-type_<br /> | ||
|
||
All other types are collectively referred to as _custom types_. Custom types can be written using a `type-expression`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to be here? Seems redundant with the previous prose paragraph. |
||
|
||
_type-expression:<br/> | ||
primary-expression_<br/> | ||
`type` _primary-type<br/> | ||
type:<br/> | ||
primary-expression<br/> | ||
primary-type<br/> | ||
primary-type:<br/> | ||
primitive-type<br/> | ||
record-type<br/> | ||
list-type<br/> | ||
function-type<br/> | ||
table-type<br/> | ||
nullable-type<br/> | ||
primitive-type:_ one of<br/> | ||
`any anynonnull binary date datetime datetimezone duration function list logical`<br/> | ||
`none null number record table text time type` | ||
nullable-type_ | ||
|
||
The _primitive-type_ names are _contextual keywords_ recognized only in a _type_ context. The use of parentheses in a _type_ context moves the grammar back to a regular expression context, requiring the use of the type keyword to move back into a type context. For example, to invoke a function in a _type_ context, parentheses can be used: | ||
|
||
|
@@ -94,7 +96,7 @@ Value.Type( 1 as number ) // type number | |
{2} as text // error, type mismatch | ||
``` | ||
|
||
Note that the `is` and `as` operators only accept nullable primitive types as their right operand. M does not provide means to check values for conformance to custom types. | ||
Note that the `is` and `as` operators only accept a _primitive or nullable primitive type_ (i.e. a _non-custom type_) as their right operand. M does not provide means to check values for conformance to custom types. | ||
|
||
A type `X` is _compatible_ with a type `Y` if and only if all values that conform to `X` also conform to `Y`. All types are compatible with type `any` and no types (but `none` itself) are compatible with type `none`. The following graph shows the compatibility relation. (Type compatibility is reflexive and transitive. It forms a lattice with type `any` as the top and type `none` as the bottom value.) The names of abstract types are set in _italics_. | ||
|
||
|
@@ -209,28 +211,28 @@ A conforming value may contain field names not listed in the field specification | |
|
||
Any function value conforms to the primitive type `function`, which does not place any restrictions on the types of the function's formal parameters or the function's return value. A custom _function-type value_ is used to place type restrictions on the signatures of conformant function values. | ||
|
||
_function-type:_<br/> | ||
`function (` _parameter-specification-list<sub>opt</sub>_ `)` _function-return-type<br/> | ||
function-type:_<br/> | ||
`function (` _parameter-specification-list<sub>opt</sub>_ `)` _return-type<br/> | ||
parameter-specification-list:<br/> | ||
required-parameter-specification-list<br/> | ||
required-parameter-specification-list_ `,` _optional-parameter-specification-list<br/> | ||
optional-parameter-specification-list<br/> | ||
required-parameter-specification-list:<br/> | ||
required-parameter-specification<br/> | ||
required-parameter-specification_ `,` _required-parameter-specification-list<br/> | ||
required-parameter-specification_ `,` _required-parameter-specification-list<br/> | ||
required-parameter-specification:<br/> | ||
parameter-specification<br/> | ||
optional-parameter-specification-list:<br/> | ||
optional-parameter-specification<br/> | ||
optional-parameter-specification_ `,` _optional-parameter-specification-list<br/> | ||
optional-parameter-specification_ `,` _optional-parameter-specification-list<br/> | ||
optional-parameter-specification:_<br/> | ||
`optional` _parameter-specification<br/> | ||
`optional` _parameter-specification<br/> | ||
parameter-specification:<br/> | ||
parameter-name parameter-type<br/> | ||
function-return-type:<br/> | ||
parameter-name parameter-type<br/> | ||
parameter-type:<br/> | ||
assertion<br/> | ||
assertion:_<br/> | ||
`as` _nullable-primitive-type_ | ||
`as` _type_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is correct, as variables, etc., can be used in an |
||
|
||
The result of evaluating a _function-type_ is a type value whose base type is `function`. | ||
|
||
|
@@ -363,7 +365,7 @@ Value.Type( Value.ReplaceType( {1}, type {number} ) | |
|
||
Type equivalence is not defined in M. An M implementation may optionally choose to use its own rules to perform equality comparisons between type values. Comparing two type values for equality should evaluate to `true` if they are considered identical by the implementation, and `false` otherwise. In either case, the response returned must be consistent if the same two values are repeatedly compared. Note that within a given implementation, comparing some identical type values (such as `(type text) = (type text)`) may return `true`, while comparing others (such as `(type [a = text]) = (type [a = text])`) may not. | ||
|
||
Compatibility between a given type and a nullable primitive type can be determined using the library function `Type.Is`, which accepts an arbitrary type value as its first and a nullable primitive type value as its second argument: | ||
Compatibility between a given type and a _non-custom type_ can be determined using the library function `Type.Is`, which accepts an arbitrary type value as its first and a _primitive or nullable primitive_ value as its second argument: | ||
bgribaudo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```powerquery-m | ||
Type.Is(type text, type nullable text) // true | ||
|
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.
Still some prose references to 'primtive-or-nullable-primitive-type' around here.