[xquery-talk] static typing of XQuery?
mhk at mhk.me.uk
Wed Sep 20 23:30:38 PDT 2006
> Does Saxon implement full "optimistic static typing" or just
> some ad-hoc subset? By the former I mean the type system of
> the FS but, but with more lenience ("optimism")? If so, it
> seems that implementing full static type checking should not
> be difficult.
My inference rules are sometimes weaker than those in FS, sometimes
Examples of weaker rules: I only analyze the child and attribute axes; I
don't infer union types (instead using the lowest common supertype).
Examples of stronger rules: variables and functions have a type inferred
from their expression body if no type is declared; constant subexpressions
take their actual (dynamic) type.
The "optimism" doesn't relate to the inference rules themselves, but to what
is treated as an error. If the static type is disjoint from the required
type I report a compile-time error; if they overlap then I generate run-time
type-checking code. As a special case, if the only value in the intersection
of the static type and the required type is the empty sequence, I report a
compile time warning (for example, when the static type is string? and the
required type is integer?).
> My feeling (which seems to match yours) is that optimistic
> static typing is useful and should perhaps be the default
> (pending further experience), but pessimistic/strict typing
> would be nice to have as an option for those who want it, but
> should not be the default.
I'll await practical experience before deciding that pessimistic static
typing is ever beneficial.
More information about the talk