[xquery-talk] static typing of XQuery?

Michael Kay mhk at mhk.me.uk
Wed Sep 20 21:06:04 PDT 2006

> How much interest is there in the "static typing" feature?

There seem to be two clusters of interest in it: (a) Microsoft, and (b)

> Which (current, actively maintained, aiming for completeness) 
> implementations implement the static typing feature?
> As the SVN version of Qexo now passes more and more of the 
> testsuite, I'm considering whether to tackle static typing.

I think that schemaless data is an important use case, and in my view
pessimistic static typing is unusable with schemaless data. It requires
constant assertions about cardinality, for example

concat(firstname, lastname)

has to be rewritten as

concat(zero-or-one(firstname), zero-or-one(lastname))

Or perhaps frustrated users will get into the habit of writing

concat(firstname[1], lastname[1])

which is really bad, because it suppresses the run-time type checking.

Doing pessimistic static typing for schema-aware queries is more reasonable,
but there are still many cases where intermediate results are likely to be
untyped. My advice would be to steer well clear. Optimistic static typing
(reporting errors only where the static type is disjoint from the required
type), as implemented in Saxon, seems to be quite good at catching a wide
class of programming mistakes.

Michael Kay

More information about the talk mailing list