Re: Unique Keys

From: Kenneth Downs <firstinit.lastname_at_lastnameplusfam.net>
Date: Sat, 27 Nov 2004 22:02:59 -0500
Message-ID: <3orn72-kja.ln1_at_pluto.downsfam.net>


Paul wrote:

> Kenneth Downs wrote:

>> In another subthread of this thread I suggested a datatype interval,
>> composed of an ordered pair of any two values of the same base type,
>> (a,b)
>> where a<=b.  Equality could then be defined as:
>> 
>> where x = (a,b)
>> and   y = (c,d)
>> 
>> x = y iff (a <= c <= b) OR (a <= d <= b)

>
> But as Mikito pointed out, for equality you want the property that:
>
> if x=y and y=z, then x=z.

Hmmm, yes indeed.

x = (1,3)
y = (2,5)
z = (4,6)

so we have x=y and y=z, but x!=z.

I will fall back somewhat to the fact that the definition (corrected for the cases you mention below) still allows for unique and referential checks of the sort I need. Can all the operators be reconciled though? There is also greater than. Is (2,3) > (1,5)? Can they be equal and unequal at the same time?

The balance of concerns is thus:

  1. Allowing the equality as I've defined gives unique and ref constraints, which are always simpler than coded constraints
  2. If the operators cannot be soundly defined, the type must be severely limited in its use or it will generate anomalies.

This is off the top of my head, but the limitation idea is more appealing. More on this after I've worked through it a little more.

>
> And this isn't true in this case.
>
> Also, what about the case where the interval (c,d) totally overlaps the
> interval (a,b)? e.g. x = (2,3) and y = (1,4)?
>
> Paul.

Well pointed out, if overlap is to map to equality, then these also would be equal.

-- 
Kenneth Downs
<?php $sig_block="Variable scope? What's that?";?>
Received on Sun Nov 28 2004 - 04:02:59 CET

Original text of this message