W3C home > Mailing lists > Public > public-qt-comments@w3.org > November 2003

RE: [F&O] 15.1 zero-or-one, one-or-more, exactly-one

From: Kay, Michael <Michael.Kay@softwareag.com>
Date: Sat, 22 Nov 2003 23:22:04 +0100
Message-ID: <DFF2AC9E3583D511A21F0008C7E62106073DD2D2@daemsg02.software-ag.de>
To: Dimitre Novatchev <dnovatchev@yahoo.com>, public-qt-comments@w3.org
> Section 15.1 Functions and Operators on Sequences defines the 
> functions  zero-or-one(), one-or-more(), exactly-one().
> 
> The function definitions are:
> 
>    fn:zero-or-one($srcval as item*) as item?
>    fn:one-or-more($srcval as item*) as item+
>    fn:exactly-one($srcval as item*) as item
> 
> 
> The main purpose of these functions is to raise an error if 
> the property they name is not true for the parameter-sequence. 
> 
> Such functions are not necessary and useful, because, had 
> their type been specified as:
> 
>    fn:zero-or-one($srcval as item?) as item?
>    fn:one-or-more($srcval as item+) as item+
>    fn:exactly-one($srcval as item) as item
> 
> then the error would be raised automatically if $srcval was 
> not of the correct type.

The problem arises when you are using a system that does (pessimistic)
static type checking. In this case, calling a function whose argument is
declared as element() with the actual argument book/author can give you a
type error even if you know that book/author will return a single element.
Calling the function with exactly-one(book/author) prevents the static type
system giving you an error (in much the same way as a treat expression). If
the type signature of exactly-one were as you suggest, then the function
would not serve its purpose, since the call exactly-one(book/author) would
again give you the static type error.

Michael Kay


> 
> Such automatic errors would be raised for any function when 
> passed parameters not matching the defined types of its 
> arguments -- therefore the above three functions are not 
> necessary at all.
> 
> Solution: remove the functions fn:zero-or-one(), fn:one-or-more() and
> fn:exactly-one()
> 
> 
> Dimitre Novatchev
> 
> 
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
> 
Received on Saturday, 22 November 2003 17:23:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:14:28 GMT