At 7:28 PM -0700 9/25/06, Ashley Winters wrote:
On 9/25/06, Miroslav Silovic <[EMAIL PROTECTED]> wrote:
TSa wrote:

 >   role Set[::T = Item] does Collection[T] where {
 >       all(.members) =:= one(.members);
 >   };

 > Nice usage of junctions!

But buggy - one means *exactly* one. So for an array of more than 1
element, all(@array) never equals one(@array) - if they're all the same,
it's more than 1, otherwise it's 0.

Yeah, that would've been cool. Are we left with asserting
C<all(.members »=:=« one(.members))>? That'd be pretty close to the
original elegance.

Ashley Winters

Unless I'm mistaken, you may be going about this the wrong way.

Within a system that already has an underlying set-like type, the Junction in this case, a test for uniqueness is (pardon any spelling):

  all(@items).elements.size === @items.size

The all() will strip any duplicates, so if the number of elements in all(@items) is the same as @items, then @items has no duplicates.

Similarly, if @items is a list of Pair (such as when you're implementing a Mapping), and you want to assert that their keys are all distinct, then this variation (pardon any spelling) would do it:

  all(@items.map:{ .key }).elements.size === @items.size

Incidentally, a unique-key constraint on an RM relation or table is like the latter as well, but substitute "key" for the name(s) of the attribute or column.

On the other hand, if you're using the above Set to implement the Junction in the first place, we can't use all/any/one/none etc in the definition.

-- Darren Duncan

Reply via email to