- From: Howard Katz <howardk@fatdog.com>
- Date: Thu, 21 Apr 2005 07:41:24 -0700
- To: "Eric Prud'hommeaux" <eric@w3.org>
- Cc: "RDF Data Access Working Group" <public-rdf-dawg@w3.org>
> -----Original Message-----
> From: public-rdf-dawg-request@w3.org
> [mailto:public-rdf-dawg-request@w3.org]On Behalf Of Eric Prud'hommeaux
> Sent: Thursday, April 21, 2005 12:06 AM
> To: Howard Katz
> Cc: RDF Data Access Working Group
> Subject: Re: XQuery value comparisons (Part I - numerics)
[ snip ... ]
> declare namespace test = "http://foo.example/"
> define function test:imafloat($num as xs:float) as xs:boolean {
> return $num instance of xs:decimal
> }
>
> will see the argument as a float in the function regardless of its
> lineage.
>
> test:imafloat(xs:decimal(5)) => false
>
> Conversely, subtype substitutions retain their origonal type:
>
> define function test:imapostitiveInteger($num as xs:integer)
> as xs:postitiveInteger {
> return $num instance of xs:postitiveInteger
> }
>
> test:imapostitiveInteger(xs:postitiveInteger("true")) => true
>
>
> Having framed this, does XQuery-instance-of pay attention to the type
> tree? I.E., does
> xs:postitiveInteger("true") instance of xs:integer
> return true or false?
Neither: it throws a type exception on the cast (or construction, which ever
way you want to look at it): "can't convert string 'true' to integer".
However if you said (and I know this is what you intended :-),
xs:positiveInteger(xs:boolean("true")) instance of xs:integer
you'd get a true, because xs:positiveInteger is a subtype of xs:integer. So
yes, "instance of: " pays attention to the tree (which means that your two
functions above aren't testing type promotion vs subtype substitution but
rather the type-tree awareness of instance of.
Howard
Received on Thursday, 21 April 2005 14:41:32 UTC