is_equal implies same_type?

This is a discussion on is_equal implies same_type? within the Eiffel forums in Programming Languages category; I was just wondering; can anyone give me a realistic example of two objects which could be considered equal, but are of different types? The only examples I can think of are types of numbers, where a float and a complex number with no imaginary part could be equal, but that's probably better dealt with by a conversion from float to complex and then comparing the complex numbers. Similarly with strings stored in different representations. Simon -- ROLF - The RISC OS Look and Feel on Linux. http://stoppers.drobe.co.uk http://ro-lookandfeel.blogspot.com/...

Go Back   Application Development Forum > Programming Languages > Eiffel

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 05-26-2008, 02:56 PM
Simon Willcocks
Guest
 
Default is_equal implies same_type?

I was just wondering; can anyone give me a realistic example of two objects
which could be considered equal, but are of different types?

The only examples I can think of are types of numbers, where a float and a
complex number with no imaginary part could be equal, but that's probably
better dealt with by a conversion from float to complex and then comparing
the complex numbers. Similarly with strings stored in different
representations.

Simon

--
ROLF - The RISC OS Look and Feel on Linux.
http://stoppers.drobe.co.uk
http://ro-lookandfeel.blogspot.com/
Reply With Quote
  #2  
Old 05-26-2008, 04:07 PM
Georg Bauhaus
Guest
 
Default Re: is_equal implies same_type?

Simon Willcocks wrote:
> I was just wondering; can anyone give me a realistic example of two objects
> which could be considered equal, but are of different types?


Any object that is just as good as some others, with respect
to a given use case involving these objects.

I have used programmer defined equality (and "less than") when
storing objects in sets for the purposes of a simple graph algorithm.
Granted, these were rooted at the same base type, but still
the analog of CIRCLE was just as good as the analog of TRIANGLE.

Another case is when I want to know whether any two objects
are different, and not use reference equality for the comparison
(thinking of persistent featuers, say).
I then have two types inherit deferred UNIQUE_ID which
happens to be a factory of GUIDs, and any object other
than Void is equal to itself only, no matter what type.
Reply With Quote
  #3  
Old 05-27-2008, 04:54 AM
Simon Willcocks
Guest
 
Default Re: is_equal implies same_type?

In message <483b1886$0$27453$9b4e6d93@newsspool4.arcor-online.net>
Georg Bauhaus <see.reply.to@maps.futureapps.de> wrote:

> Simon Willcocks wrote:
> > I was just wondering; can anyone give me a realistic example of two objects
> > which could be considered equal, but are of different types?

>
> Any object that is just as good as some others, with respect
> to a given use case involving these objects.


I'm not sure I follow you here, but I think you are describing what objects
can be compared to each other, in which case I didn't make myself clear,
sorry. I am looking for an example where a comparison feature (equal or
is_equal) returns True although the two objects being compared are of
different types.

> I have used programmer defined equality (and "less than") when
> storing objects in sets for the purposes of a simple graph algorithm.
> Granted, these were rooted at the same base type, but still
> the analog of CIRCLE was just as good as the analog of TRIANGLE.


OK, but a CIRCLE would never be equal to a TRIANGLE, would it?

> Another case is when I want to know whether any two objects
> are different, and not use reference equality for the comparison
> (thinking of persistent featuers, say).
> I then have two types inherit deferred UNIQUE_ID which
> happens to be a factory of GUIDs, and any object other
> than Void is equal to itself only, no matter what type.


I don't see the difference between that and reference equality, sorry.
However, if an object is only equal to itself, then objects can still only
be equal if they are the same type.

Thanks for replying.

Simon

--
ROLF - The RISC OS Look and Feel on Linux.
http://stoppers.drobe.co.uk
http://ro-lookandfeel.blogspot.com/
Reply With Quote
  #4  
Old 05-29-2008, 04:56 AM
Ulrich Windl
Guest
 
Default Re: is_equal implies same_type?

Simon Willcocks <simon.willcocks@t-online.de> writes:

> I was just wondering; can anyone give me a realistic example of two objects
> which could be considered equal, but are of different types?
>
> The only examples I can think of are types of numbers, where a float and a
> complex number with no imaginary part could be equal, but that's probably
> better dealt with by a conversion from float to complex and then comparing
> the complex numbers. Similarly with strings stored in different
> representations.


I don't know a good example, but maybe like this:

class EYE

class EUROPEAN_EYE inherit EYE

class AFRICAN_EYE inherit EYE

e1, e2 : EYE

e1 := create brown EUROPEAN_EYE
e2 := create brown AFRICAN_EYE

assuming that equal in EYE is not redefined in any ancestor, both brown EYEs
(e1, e2) might be considered equal (although having a different dynamic type).

Ulrich
Reply With Quote
  #5  
Old 06-02-2008, 11:06 AM
Simon Willcocks
Guest
 
Default Re: is_equal implies same_type?

In message <87abi9cwuc.fsf@pc9454.klinik.uni-regensburg.de>
Ulrich Windl <Ulrich.Windl@RZ.Uni-Regensburg.DE> wrote:

> Simon Willcocks <simon.willcocks@t-online.de> writes:
>
> > I was just wondering; can anyone give me a realistic example of two
> > objects which could be considered equal, but are of different types?

>
> I don't know a good example, but maybe like this:
>
> class EYE
>
> class EUROPEAN_EYE inherit EYE
>
> class AFRICAN_EYE inherit EYE
>
> e1, e2 : EYE
>
> e1 := create brown EUROPEAN_EYE
> e2 := create brown AFRICAN_EYE
>
> assuming that equal in EYE is not redefined in any ancestor, both brown
> EYEs (e1, e2) might be considered equal (although having a different
> dynamic type).


But what would be the difference between European and African eyes?
Presumably there must be some fundamental difference (otherwise there would
be no point in having different classes for them), so there will be some
feature that behaves differently even though the objects are the same, which
seems wrong, to me.

Specifically to your example, I'd agree that equal( e1.colour, e2.colour )
holds, but I can't see equal( e1, e2 ) holding.

Simon

--
ROLF - The RISC OS Look and Feel on Linux.
http://stoppers.drobe.co.uk
http://ro-lookandfeel.blogspot.com/
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:04 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.