Chapter 14. Static Typing
Errors in a query can be reported in either the static analysis phase or the dynamic evaluation phase. These two phases are roughly analogous to compiling and running program code. Certain XQuery implementations take a more aggressive approach to finding type-related errors in the static analysis phase. These implementations are said to support static typing.
What Is Static Typing?
Static typing, as the term is used in XQuery, refers to reporting all possible type errors at analysis (compile) time rather than evaluation (run) time. This is sometimes referred to as pessimistic static typing, where the philosophy is to report any errors that could possibly happen, not just those that it knows will happen. The static typing feature of XQuery is optional; implementations are not required to support static typing and many do not fully support it.
The fact that a processor doesn't support this feature doesn't mean that it is doing no compile-time analysis. It might use the analysis transparently for optimization purposes, or it might report some errors at compile time; but in this case, it will report errors optimistically. It will only report errors when it can see that there is definitely something wrong, like in the expression "x" + 3, and not simply in cases of ambiguity, as in $x + 3, where the value of $x depends on some input data.
Static typing has the advantages of allowing type errors to be caught earlier and more reliably, and can help some implementations ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access