Re: static typing and computed elements

On Thu, 2002-01-17 at 10:57, hme@informatik.uni-rostock.de wrote:
> Hello Jerome,
> 
> You (Jerome Simeon) wrote:
> > Holger,
> > 
> > The XQuery static typing handles dynamic element names fine. The trick
> > is to realize that wildcard names are part of the type system and can be
> > used to type such an operation.
> > 
> > For instance:
> > 
> > element title { "Lord of the Rings" }
> >  has type
> > element title { xs:string }
> > 
> > and:
> > 


> > 
> > where the * is a wildcard that stands for all possible QNames.
> > 
> > So you can statically type this expression without problem, you just get
> > a less precise type.
> 
> A type that stands for all possible types precisely.

Note that it's only all possible types for the element *name*. The
content of the element itself is still precisely typed (here
xsd:string), based on the expression that computes the content of the
element.

> If the evaluation
> generates a value that is not a QName at all than a dynamic type
> exception happens?  Or did XQuery not check the type during the
> evaluation phase in this circumstance?
> 

No, this would be checked statically too. The typing rule looks like:

        e1 : xs:qname   e2 : t2
  ------------------------------------------
   element { e1 } { e2 } : element * { t2 }

So e1 needs to be of type qname otherwise it is ill-typed. But in all
cases, the type for the resulting element does not know which will be
the actual qname, hence the element * { t2 } type.

Well I guess it means my query above was not quite right, and should
look like:

element { if $language = "french"
          then xf:qname("titre")
          else xf:qname("title") }
        { "LoTR" }

Where:

      if $language = "french"
          then xf:qname("titre")
          else xf:qname("title")

has type xs:qname

and the whole expression has type: element * { xs:string }

> Is that really static typing anymore?
> 

I believe it is :)

More seriously, I think XML and XML Schema are quite flexible models and
schema language and so I think we need a type system that provides the
same flexibility. We certainly need to deal with both well-formed and
validated documents and the XQuery type system supports both.

- Jerome


> > You can see more details about the typing for element constructors in
> > section 4.4 of the XQuery formal semantics (June working draft).
> 
> You are right, I'll have a closer look at that draft.
> 
> Regards
> 
> Holger
> 
> -- 
> Holger Meyer, Uni of Rostock, Dpt. of CS, DB Research Group
> hm at GUUG.de, http://www.informatik.uni-rostock.de/~hme/
> 

Received on Thursday, 17 January 2002 12:19:12 UTC