What's the difference between equality and identity?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

What's the difference between equality and identity?

Costello, Roger L.
Hi Folks,

In section "3.2.1 The Attribute Declaration Schema Component" of the structures specification it discusses attribute default and fixed values.

It contains this sentence:

    Note that it is values that are checked, not strings,
    and that the test is for either equality or identity.

What is a test for "identity?"

Suppose I declare an attribute:

    <attribute name="number" type="integer" fixed="1" />

And in an XML instance I use the attribute:

    number="1.0"

Is 1.0 equal to 1, but not identical?

The sentence says "the test is for either equality or identity."  Does that mean one schema validator implementation can elect to test for equality while another implementation can elect to test for identity?

Will

    number="1.0"

be schema valid with one implementation and schema invalid with another?

/Roger

P.S. At the beginning of that paragraph it says:

    The {value constraint} property reproduces ...

I believe it should say:

    The {variety} property reproduces ...



Reply | Threaded
Open this post in threaded view
|

Re: What's the difference between equality and identity?

Michael Kay

On 18/07/2012 13:30, Costello, Roger L. wrote:

> Hi Folks,
>
> In section "3.2.1 The Attribute Declaration Schema Component" of the structures specification it discusses attribute default and fixed values.
>
> It contains this sentence:
>
>      Note that it is values that are checked, not strings,
>      and that the test is for either equality or identity.
>
> What is a test for "identity?"
The distinction is explained here:
http://www.w3.org/TR/xmlschema11-2/#value-space

For example:

* positive and negative zero are equal but not identical.

* NaN is identical to itself but not equal to itself.

In XSD (unlike XPath) a value is never equal (nor identical) to a value
of a different primitive type - so an integer can never equal a double.

There are in fact very few cases where equality tests and identity tests
give different results. At one time there were more. For example, the
xs:time values 00:00:00 and 24:00:00 are both equal and identical (IIRC,
at one stage during development, they were equal but not identical).
Similarly the durations P1Y and P12M are both equal and identical.

Michael Kay
Saxonica

Reply | Threaded
Open this post in threaded view
|

Re: What's the difference between equality and identity?

C. M. Sperberg-McQueen-2
In reply to this post by Costello, Roger L.

On Jul 18, 2012, at 6:30 AM, Costello, Roger L. wrote:

> Hi Folks,
>
> In section "3.2.1 The Attribute Declaration Schema Component" of the structures specification it discusses attribute default and fixed values.
>
> It contains this sentence:
>
>    Note that it is values that are checked, not strings,
>    and that the test is for either equality or identity.
>
> What is a test for "identity?"

It is a test, given a value called X and a value called Y, to
see whether value X and value Y are the same value or
not the same value.

I see that Michael Kay has already pointed to the discussion
of the distinction in the Datatypes 1.1 spec, which addresses
the distinction between equality and identity more explicitly
than was done in 1.0.

>
> Suppose I declare an attribute:
>
>    <attribute name="number" type="integer" fixed="1" />
>
> And in an XML instance I use the attribute:
>
>    number="1.0"
>
> Is 1.0 equal to 1, but not identical?

Well, there's an irrelevant complication in your example:  "1.0" is
not allowed as a lexical representation for an attribute declared
as integer, because it contains a decimal point.

But if we take the similar example where the attribute is declared
as being of type decimal, then the lexical forms "1" and "1.0"
denote the same value.  The fixed-value constraint and the value
given in the instance will compare both equal and identical.  
(It is the lexical forms that are different, not the values.)

> The sentence says "the test is for either equality or identity."  Does that mean one schema validator implementation can elect to test for equality while another implementation can elect to test for identity?

No; if that were the intention, the spec would say that it was
implementation-defined (or implementation-dependent) whether
the test was for equality or for identity.  The sentence you quote
just means the test succeeds if the values are equal, or identical,
or both.

>
> Will
>
>    number="1.0"
>
> be schema valid with one implementation and schema invalid with another?

I would not expect the result to differ between conforming implementations,
no.

>
> /Roger
>
> P.S. At the beginning of that paragraph it says:
>
>    The {value constraint} property reproduces ...
>
> I believe it should say:
>
>    The {variety} property reproduces ...


Thanks.

When I look at the paragraph, though, I think the sentence is correct as it
stands:  it's not the {variety} property that reproduces in an XSD context the
functionality of default and #FIXED attribute declarations in DTDs, but the
{value constraint} property as a whole.  The {variety} property distinguishes
between default and fixed values, but it does not specify which value is to
serve as the default or fixed value, and without that, the functionality of
the corresponding declarations in DTDs hasn't been reproduced.
 
--
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com 
* http://cmsmcq.com/mib                 
* http://balisage.net
****************************************************************