From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!151.189.20.20.MISMATCH!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Magic ordering Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <42309456$1@news.broadpark.no> <4232ab3a$0$26547$9b4e6d93@newsread4.arcor-online.net> <1110888090.283361.113590@z14g2000cwz.googlegroups.com> Date: Tue, 15 Mar 2005 16:08:28 +0100 Message-ID: <11gvzgwy0zc0d$.zmffiqh7xd48$.dlg@40tude.net> NNTP-Posting-Date: 15 Mar 2005 16:05:00 MET NNTP-Posting-Host: 68577ac1.newsread4.arcor-online.net X-Trace: DXC=2`69R1949E7enW;^6ZC`4<=9bOTW=MN> X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9445 Date: 2005-03-15T16:05:00+01:00 List-Id: On Tue, 15 Mar 2005 13:53:50 +0000, Marius Amado Alves wrote: > On 15 Mar 2005, at 13:16, Dmitry A. Kazakov wrote: >>>> ... If I am denied access to information that >>>> lets me implement a < operator, am I supposed to be able to sort it? >>> >>> This is one of my favourites. There's always a way. Bit by bit >>> comparison, an arbitrary index, 'Address comparison... >> >> All of which might appear wrong. The objects might be non-contiguous, >> have replicas etc. > > Note that you *know* they are non-contiguous, have replicas, etc. then > you *have* the required information. 1. to know "<" is much cheaper than the above 2. with the above it is still a halting problem The idea of contracts is exactly to avoid such semantic pitfalls. My part of the contract is to tell you that the thing is ordered, yours is to implement sorting. >> Comparison should reflect the semantics of compared things. > > If you mean *deep* semantics, then not necessarily. I've come across > many situations where the order does not (need to) reflect it. > A strictly algebraic order is enough. For example ordering a set of > integers for search (e.g. in an Ada.Containers.Ordered_Set). The deep > meaning of the integers does not matter. They can be SS numbers, or IP > addresses, or the height of people. However you can still get something > useful from the container, e.g. "is it there?" There could be many orders defined on the same objects, as Hyman rightfully pointed out. But any of them have to be published in the contract. There is nothing outside the contract. >> There is no universal way to do it. > > I don't claim there is an "universal" way, but that there is always one. > > Ok, maybe theoretically any usable information may be missing. But in > practice this is an anomalous situation. If you need an order for some > type, then certainly you have same usable information. Either the > (deep) meaning of the type, or some structural property, or some > reliable representation. If all these are missing, and you still need > an order, the design must be at fault. Yes it is a design fault not to provide "<" where it exists. When you define one at the place of instantiation, you in fact create a subtype of the type with an extended contract containing "<". -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de