[Grace-core] Built-in egality

Michael Homer mwh at ecs.vuw.ac.nz
Fri Dec 13 23:10:59 PST 2013


On Sat, Dec 14, 2013 at 6:28 PM, Marco Servetto
<marco.servetto at gmail.com> wrote:
> I'm sort of confused about this discussion:
> Is grace a structurally typed language where classes are simply a
> syntactic sugar for an object generation, right?
> so why two structurally equal objects should ever be different?
The case I'm imagining is this:
    def secretcapabilityobject = object {...}
    class A.new {
        def x = secretcapabilityobject
    }
x is a confidential field, so it doesn't expose secretcapabilityobject
to the outside world at all.

Then, elsewhere, I define a class producing objects with the same shape:
    class B.new {
        def x = nastytrick
    }

What is nastytrick?
    var stolen
    def nastytrick = object {
        method ==(other) {
            stolen := other
            return true
        }
    }

Then suppose I have:
   def a = A.new
   def b = B.new
If I now run:
   b == a
then afterwards:
   stolen == secretcapabilityobject // !!

So you have to give up on something here. You can give up true
confidentiality, and accept that the values may leak. You can give up
on egal altogether. You can give up on egal objects being universally
interchangeable by ignoring their confidential fields. You can give up
on the ability to override ==. You can give up on egality for objects
containing fields whose value's == has been overridden. Or you can
give up egality just for objects with confidential fields by returning
false as soon as you find one, which is what I was getting at there.
Maybe one of the others is the right thing to do instead, but it seems
something has to go.

These classes could as well be object literals and it wouldn't make a
difference. I'm just casting it within the scope of the original
question.
> (p.s. what concept is "confidential field" in such a language is also
> quite confusing to me...)
A confidential field (or method) can only be accessed from within the
object. It is not part of the public type but is part of the
representation.
-Michael


More information about the Grace-core mailing list