| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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/ |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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/ |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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/ |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.