The `==' operator (Re: [nem-en] Nemerle 0.2.0 released)
Michal Moskal
malekith at pld-linux.org
Mon Sep 13 22:39:34 CEST 2004
On Mon, Sep 13, 2004 at 10:15:21PM +0200, Kamil Skalski wrote:
> On Mon, Sep 13, 2004 at 10:03:14PM +0200, Michal Moskal wrote:
> > On Mon, Sep 13, 2004 at 08:27:17PM +0200, Kamil Skalski wrote:
> > > On Mon, Sep 13, 2004 at 07:04:43PM +0200, Michal Moskal wrote:
> > > > On Mon, Sep 13, 2004 at 12:36:17PM -0400, Mark Friedman wrote:
> > > > > I'm curious about the rationale for having the '==' operator not
> > > > > fallback to reference equality? I guess that it's not entirely clear
> > > > > to me what the '==' operator actually means in Nemerle.
> > > >
> > > > It works the same as in C#, that it is statically resolved whatever class
> > > > of the left or right parameter (or any base class thereof) has an overload
> > > > on ==. Some classes (like System.String or System.Decimal) have it.
> > > >
> > > > However C# has an additional fallback case -- if there is no matching
> > > > overload, reference equality is used. That is == checks if objects on
> > > > both sides are physically the same.
> > >
> > > This description is not clear. Why "or any base class thereof" doesn't
> > > refer also to System.Object? Object is base of all the classes, so
> > > simply the rule "whatever class of the left or right parameter (or any
> > > base class thereof) has an overload" is always satisfied. This way
> > > specification of how it works in C# is indeed clear and consitant -
> > > it chooses the nearest possible overload.
> >
> > Nope, System.Object hasn't got == overload ;) It's special case as
> > usual.
>
> Nope, it has:
>
> The predefined reference type equality operators are:
>
> bool operator ==(object x, object y);
> bool operator !=(object x, object y);
>
> The operators return the result of comparing the two references for
> equality or non-equality.
>
> Since the predefined reference type equality operators accept operands
> of type object, they apply to all types that do not declare applicable
> operator == and operator != members. Conversely, any applicable
> user-defined equality operators effectively hide the predefined
> reference type equality operators.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_7_9_6.asp
This is C# spec. Run ildasm on mscorlib.dll. There is no
System.Object.op_Equality.
> Btw, what is the difference betwen
> public static @== (x : object, y : object) : bool { x.ReferenceEqulity (y) }
> and special case you are refering to?
It will catch all == uses, not only these with object on either side.
--
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: ::: Logic is a nice contrast to the Real World. :: UL++++$ C++ E--- a?
More information about the devel-en
mailing list