Re: Sequence type and other related questions

Paul,

The type system of XPath and XQuery is (based on) XML Schema. XML Schema
provides types for sequences of items (or nodes). The connection between
XML Schema and the XPath and XQuery type system is described in the
XQuery 1.0 and XPath 2.0 Formal Semantics, which is what Torsten pointed
you to.

For instance, the following XML Schema element declaration:

<xs:element name="a" type="T"/>
<complexType name="T">
  <xs:sequence>
    <xs:element name="b" type="xs:string"/>
    </xs:element name="c" type="xs:integer" maxOccurs="unbounded"/>
  </xs:sequence>
</complexType>

In the XQuery type system, this is written as:

define element a of type T
define type T {
  element b of type xs:string,
  element c of type xs:integer+
}

The key point here is that the content model of a complex type
effectively acts as a 'type' for a sequence of items (nodes).

At the XQuery type system level, that means:

  element b of type xs:string, element c of type xs:integer+

is a type of a sequence of one element containing a string, followed by
one or more elements c of type xs:integer.

Finally, there is a connection with 'SequenceTypes' in XQuery.
SequenceTypes are used to refer to XML Schema types, but can also
indicate a collection (using an occurrence indicator).

For instance:

The sequence type: element(a)+
Corresponds to the type: element a+ in the XQuery type system.

However, sequence types cannot express all kinds of sequences from
schema (they cannot express choice, all groups, or sequences of
heterogeneous elements).

Hope this helps,
- Jerome

On Tue, 2003-07-15 at 12:18, Paul Duffin wrote:
> Torsten,
>      It does a little.
> 
> I am more interested in the usage of this within XPath than in XQuery. I 
> am not sure whether this mailing list is the right one to use it is just 
> it is referred to from the same page that refers to the XPath/XQuery 
> model and functions / operators.
> 
> I cannot find anything within the XPath specifications that relate to 
> this. The closest I found was the SequenceType but that does not appear 
> to match what you describe below.
> 
> Torsten Grust wrote:
> > Paul,
> > 
> >   does the following help?
> > 
> > On July 15 (11:03 +0100), Paul Duffin wrote with possible deletions:
> > |
> > | The section on sequences
> > | (http://www.w3.org/TR/xpath-datamodel/#sequences) states that a sequence
> > | that contains a single item is indistinguishable from the item itself.
> > | Among other things this means that a sequence with one item in it has
> > | the same type as that item. Therefore sequences must have types.
> > |
> > | This raises a couple of questions.
> > |
> > | What is the type of a sequence with two (or more) items in it which are
> > | potentially different ?
> > |
> > | Is it just a generic sequence type, is it the type which is the closest
> > | ancestor of all the item types, or something else ?
> > 
> > For two items x and y of types s and t, respectively, the sequence
> > value (x,y) has type s,t.  Note that (.,.) (the ``comma'') is used as
> > a binary type constructor in forming the type s,t.
> > 
> > As a derivation rule:
> > 
> >                     E |- x:s   E |- y:t
> >                    ---------------------
> >                      E |- (x,y) : s,t
> > 
> > 
> > What you refer to above (``closest ancestor'') might be related to
> > approximations of such sequence types:
> > 
> > The XQuery Formal Semantics sometimes compute (more or less rough)
> > approximations of these types (e.g., during the typing of a for-bound
> > variable).   An approximation of the type  s,t  is
> > 
> >                               (s | t)+
> > 
> > computed as
> > 
> >                         prime (s,t) quantifier (s,t)
> >                         \_________/ \______________/
> >                           = s | t        = +
> > 
> > Note that information about the order of s and t in the original type
> > as well as information about the exact number of occurrences of s and
> > t in the original type are lost.  We do however have
> > 
> >                             s,t <: (s | t)+
> > 
> > which ensures that typing the rest of program using the approximation
> > is safe.
> > 
> > | What is the type of an empty sequence ?
> > 
> > The type of the empty sequence is the special type empty.
> > 
> > 
> > Greetings,
> >    --Torsten
> > 
> > --
> >   | Dr. Torsten Grust                          Torsten.Grust@uni-konstanz.de |
> >   |                                   http://www.inf.uni-konstanz.de/~grust/ |
> >   | Database Research Group, University of Konstanz (Lake Constance/Germany) |
> >   |             (Please avoid sending me MS Word or PowerPoint attachments.) |
-- 
Jerome Simeon <simeon@research.bell-labs.com>

Received on Tuesday, 15 July 2003 12:43:13 UTC