From 649a6d50cd9a8e14a6e2262f82bcbfe46cbe301c Mon Sep 17 00:00:00 2001
From: Michael Kay
It is a
In many situations the terms $x instance of xs:string*
, the construct xs:string*
+ uses the
- item()
, which matches all items, xs:error
,
- which matches no items, and
Whenever it is necessary to refer to a type in an &language; expression, the
In many situations the terms $x instance of xs:string*
, the construct xs:string*
- uses the
Two element()
and element(*)
are equivalent,
- as are attribute(A)
and attribute(A, xs:anySimpleType)
.
With the exception of the special type
empty-sequence()
, a item()
,
which permits any kind of item, item types divide into element()
), xs:integer
) and function types
(such as function() as item()*
).
- eq
operator.
Item types representing element
-and attribute nodes may specify the required element(*, us:address)
-denotes any element node whose type annotation is (or is derived from)
-the schema type named us:address
.
The occurrence indicators +
, *
, and ?
bind to the last +
, *
, and ?
+ bind to the last
us:address
.
+
While this definition is adequate for the purpose of defining the syntax + of &language;, it ignores the fact that there are also item types that cannot be + expressed using &language; syntax: specifically, item types that reference + an anonymous simple type or complex type defined in a schema. Such types + can appear as type annotations on nodes following schema validation.
In most cases, the set of items matched by an item type consists either
+ exclusively of item()
, which matches all items, xs:error
,
+ which matches no items, and
Two element()
and element(*)
are equivalent,
+ as are attribute(A)
and attribute(A, xs:anySimpleType)
.
+ eq
operator.
us:address
.
Some of the constructs described in this section include a Node types are The syntax for node types is also used for Some of the constructs described in this section include a In these constructs, the type name T is expanded using the Like other lexical QNames, the type name T is expanded using the
Where a A A The keywords If the An xs:integer
) or imported from a schema,
@@ -4450,16 +4458,23 @@ declare variable $orange-fruit as my:fruit := "orange";
- NodeTest
rather than NodeType
.element(N, T)
attribute(N, T)
document-node(element(N, T))
xs:integer
) or a user-defined type. It must however
be the name of a type defined in a schema; it cannot be a function
and fn
are synonyms.
fn:name#1 instance of function(*)
fn{@id} instance of function(*)
fn:random-number-generator() instance of function(*)
[1, 2, 3] instance of fn(*)
{} instance of fn(*)
A
A
The keywords function
and fn
are synonymous.
In addition, a
In consequence, a
- Here are some examples of
- function(*)
matches any function, including maps and arrays.
This can also be written fn(*)
.
fn:count#1 instance of function(item()*) as xs:integer
returns true,
+ because the signature of the function item fn:count#1
+ is function(item()*) as xs:integer
.
+
- %my:assertion function(*)
matches any %my:assertion
is satisfied.
-
fn:count#1 instance of function(xs:string*) as item()
returns true,
+ because the signature of the function item fn:count#1
+ is a subtype of function(xs:string*) as item()
.
+
- function(xs:int, xs:int) as xs:int
matches any $F
is a function(xs:int, xs:int) as xs:int
.
-
This can also be written fn(xs:int, xs:int) as xs:int
.
%my:assertion
.
+
- %my:assertion function(xs:int, xs:int) as xs:int
matches any $F
is a function(xs:int, xs:int) as xs:int
- if the implementation-defined function assertion %my:assertion
is satisfied.
+ that satisfies the implementation-defined function assertion %my:assertion
.
- function(xs:anyAtomicType) as item()*
matches any map, or any function with the required signature.
function(xs:anyAtomicType) as item()*
matches any map,
+ or any other function item with the required signature.
- function(xs:integer) as item()*
matches any array, or any function with the required signature.
function(xs:integer) as item()*
matches any array,
+ or any other function item with the required signature.
An unprefixed QName is taken to refer to the namespace +
An unprefixed QName used
+ within a http://www.w3.org/2012/xquery
. Since this is a
A
An map(*)
matches any map.
The map(*)
matches any map. The map(K, V)
matches any map where every key
is an instance of K
and every value is an
instance of V
.
Although the grammar for TypedMapType
allows the key to be described using the full ItemType
syntax, the item type used must be
- a
Examples:
- -Given a map $M
whose keys are integers and whose
+
+
For example, given a map $M
whose keys are integers and whose
results are strings, such as { 0: "no", 1: "yes" }
,
- consider the results of the following expressions:
+ the following following expressions deliver the result shown:
- not($M instance of map(xs:int, xs:string))
returns true()
+ $M instance of map(xs:int, xs:string)
returns false()
- not($M instance of map(xs:integer, xs:token))
returns true()
+ $M instance of map(xs:integer, xs:token))
returns false()
Because of the rules for subtyping of function
- types according to their signature, it follows that the item type
- function(A) as item()*
, where A is an function(xs:integer) as item()*
;
- a call on the map that treats it as a function with an integer argument
- will always succeed, and will always return an empty sequence.
The function signature of a map matching type
- map(K, V)
, treated as a function, is
- function(xs:anyAtomicType) as V?
. It is thus always a
- subtype of function(xs:anyAtomicType) as item()*
regardless of the
- actual types of the keys and values in the map. The rules for
- function(xs:anyAtomicType) as xs:integer
, even when the map
- does not match in the sense required to satisfy the instance of
- operator. In such cases, a type error will occur only if an actual
- call on the map (treated as a function) returns a value that is not
- an instance of the required return type.
-
Examples:
@@ -5516,6 +5537,22 @@ name. The syntaxrecord()
is allowed; the only thing it matches is an empty map.
+
+ A
For example, the RecordType
+ record(r as xs:double, i as xs:double)
+ matches a map if the map has exactly two entries: an entry with key "r"
+ whose value is a singleton xs:double
value, and an entry with key "i"
+ whose value is also a singleton xs:double
value.
Record types describe a subset of the value space of maps. They do not define any new kinds of + values, or any additional operations. They are useful in many cases to describe more accurately the + type of a variable, function parameter, or function result, giving benefits both in the readability + of the code, and in the ability of the processor to detect and diagnose type errors and to optimize + execution.
+ +A
For example, the RecordType
- record(r as xs:double, i as xs:double)
- matches a map if the map has exactly two entries: an entry with key "r"
- whose value is a singleton xs:double
value, and an entry with key "i"
- whose value is also a singleton xs:double
value.
If the list of fields ends with ",*"
then the record type is said to be
RecordType
@@ -5549,7 +5579,7 @@ name.
The syntax record(*)
defines an extensible record type that has no explicit
field declarations. It is equivalent to the item type
- map(*)
: that is, it allows any map.
map(*)
: that is, it matches any map.
A record type can constrain only those entries whose keys are strings, but when the record @@ -5590,11 +5620,7 @@ name.
-Record types describe a subset of the value space of maps. They do not define any new kinds of - values, or any additional operations. They are useful in many cases to describe more accurately the - type of a variable, function parameter, or function result, giving benefits both in the readability - of the code, and in the ability of the processor to detect and diagnose type errors and to optimize - execution.
+If a variable $rec
is known to conform to a particular
record type, then when a lookup expression $rec?field
is used, (a) the processor
@@ -5762,6 +5788,10 @@ declare record Particle (
An
The array(*)
matches any
- array. The array(*)
matches any array.
The array(X)
matches any array
in which every array member matches the true()
+ [ [1, 2], [3, 4] ] instance of array(array(xs:integer+))
returns true()
+
An array also matches certain other
The type xs:error
has an empty value space; it never appears as a dynamic type or as the content type of a dynamic element or attribute type.
+
xs:error
+ The item type xs:error
has an empty value space;
+ it never appears as a dynamic type or as the content type of a dynamic element or attribute type.
- It was defined in XML Schema in the interests of making the type system complete and closed, and it is also available in &language;
- for similar reasons.
Even though it cannot occur in an instance, xs:error
is a valid type name in a sequence type. The