From 4baf2598525726ee49e98a69b52cad14a7a7ce99 Mon Sep 17 00:00:00 2001
From: Michael Kay
- A
An
A
In addition, a
Here are some examples of
The map(*)
matches any map. The map(X, Y)
matches any map where the type of every key
- is an instance of X
and the type of every value is an
- instance of Y
.
map(K, V)
matches any map where K
and V
.
@@ -5169,7 +5167,47 @@ name.
- Because of the rules for subtyping of function types according to their signature, it follows that the item type +
A map is also a function item, and therefore matches certain
+ function tests. Specifically, a map that matches map(K, V)
also matches a function
+ test of the form function(xs:anyAtomicType) as R
provided that both the following
+ conditions are satisfied:
V is a
empty-sequence() is a
To understand this rule, consider the use of a map $M
in a function
+ call $M($K)
, which is equivalent to the function call map:get($M, $K)
.
+ This function accepts any atomic value for the argument $K
, and hence satisfies
+ a function test that requires an argument type of xs:anyAtomicType
. If the
+ key $K
is present in the map, the result of the function will be a value of
+ type V; if not, it will be an empty sequence. The map is therefore substitutable
+ for the function test provided that the function test allows both a value of type V
+ and the empty sequence as possible results.
The key type K does not enter into this rule. That is because in the function call
+ $M($K)
, the sought key $K
does not have to be of the same
+ type as the keys actually present in the map.
The transitivity rules for item type matching mean that if an item M
+ matches a type T, and T is a map(xs:integer, xs:string)
)
+ matches function(xs:anyAtomicType) as xs:string?
+ means that it will also match other function tests such as
+ function(xs:integer) as xs:string?
and
+ function(xs:decimal) as xs:anyAtomicType?
Furthermore, the rules for
+ map(xs:integer, xs:string)
can be coerced to a function of
+ type function(xs:integer) as xs:string
; in this situation a type
+ error will occur only if a call on the function actually returns an empty sequence.
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 atomic type, also matches any map, regardless of the type of the keys actually
found in the map. For example, a map whose keys are all strings can be supplied where the required type is
function(xs:integer) as item()*
; a call on the map that treats it as a function with an integer argument will always succeed,
@@ -5177,7 +5215,7 @@ name.
The function signature of a map matching type +
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
@@ -5484,7 +5522,34 @@ declare function flatten($tree as tree) as item()* {
-
The function signature of an array +
An array that matches array(T)
+ also matches the function test function(xs:integer) as T
.
To understand this rule, consider the use of an array $A
in a function
+ call $A($I)
, which is equivalent to the function call array:get($A, $I)
.
+ This function accepts any integer for the argument $I
, and the result
+ will either be an instance of T, or an error.
The transitivity rules for item type matching mean that if an item A
+ matches a type T, and T is a array(xs:string)
)
+ matches function(xs:integer) as xs:string
+ means that it will also match other function tests such as
+ function(xs:long) as item()*
.
Furthermore, the rules for
+ array(node())
can be coerced to a function of
+ type function(xs:integer) as element()
; in this situation a type
+ error will occur only if a call on the function actually returns a node
+ that is not an element node.
The function signature of an array
matching array(X)
, treated as a function, is
function(xs:integer) as X
. It is thus always a subtype of
function(xs:integer) as item()*
@@ -5498,7 +5563,7 @@ declare function flatten($tree as tree) as item()* {
operator. In such cases, a type error will occur only if an actual
call on the array (treated as a function) returns a value that is
not an instance of the required return type.
Rules defining whether one array type is a
Both the following are true:
+All the following are true:
A is map(K, V)
B is function(xs:anyAtomicType) as W
,
- where W has the same item type as V, but also allows
- an empty sequence.
B is function(xs:anyAtomicType) as R
V ⊆ R
empty-sequence()
⊆ R