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,2ff5c149712ec0eb X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada Interfaces and the Liskov Substitution Principle Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.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: <1179953657.839272.160320@a26g2000pre.googlegroups.com> <1179991769.376381.252010@m36g2000hse.googlegroups.com> <12h6mi42jcha0.7f9vfsnihjwr$.dlg@40tude.net> <1180011507.159515.46920@o5g2000hsb.googlegroups.com> <1180079541.558215.256570@h2g2000hsg.googlegroups.com> <1180124867.710641.176330@k79g2000hse.googlegroups.com> Date: Sat, 26 May 2007 09:48:38 +0200 Message-ID: <1k165n4jwxna3$.1mpx49xvcrc0z$.dlg@40tude.net> NNTP-Posting-Date: 26 May 2007 09:48:30 CEST NNTP-Posting-Host: b99cf430.newsspool2.arcor-online.net X-Trace: DXC=IYWU5HaN:@]HigV@eW57PQA9EHlD;3YcR4Fo<]lROoRQ8kF On 25 May 2007 13:27:47 -0700, Maciej Sobczak wrote: > On 25 Maj, 10:21, "Dmitry A. Kazakov" > wrote: > >>> Interesting. In most of the cases, the factory function creates the >>> object of whatever type *it* decides (based on its parameters or some >>> other input values) and initializes the class-wide type accordingly. >> >> Not necessarily. In one case, I generate nodes of a graph. The nodes can be >> of different types regarding their persistence. For example, there are >> nodes resident in the database and nodes resident in the memory etc. Now, >> when creating a new node a factory moves along two axes: the standard >> root/branch/leaf hierarchy and persistence stuff. For the latter the >> factory receives an already existing node, to create "a new node like >> this." This is not copying. Ideally it should double dispatching along both >> axes. I have implemented it as: >> >> New_Node := Create (Get_Factory (Some_Existing_Node), ...); > > Above, it is the factory function that is "parameterized" on the left- > hand type and the right-hand one, which was the point. But it would be enough to give just two examples, one for LHS, another for RHS: X : T; begin X := Read_From_File; --- LHS return X; -- RHS in the caller > - this is still much different from assignment_statement > (wow!) between two class-wide types. How is it different? Note that there is little room for how to define assignment. Within a type hierarchy there are only four variants: T'Class x T'Class -- non-dispatching T x T'Class -- dispatches on the target (C++) T'Class x T' -- dispatches on the source T x T -- Fully dispatching (Ada*) In all cases X:=Y will be legal on two class-wide objects. > I'm still for banning it. For this you have to make assignment contravariant (non-primitive operation) in one of its arguments. That would be a total mess, because it would require overloading assignment for each derived type. For the same reason all signatures with a class-wide parameter are bad, because they lead to ambiguities in trivial cases: type S is new T with ...; X, Y : S; X := Y; -- S'Class x S'Class vs T'Class x T'Class? You will need some sort of dominance rules to resolve that. P.S. Probably you have in mind a "stratified" assignment which statically checks that LHS and RHS are of the same type. Ada has it as well. This is achieved by types cloning upon derivation: type My_Float is new Float range ...; -- equivalent to -- subtype Anonymous is My_Float range ...; -- Same hierarchy -- type My_Float is new Anonymous; -- Clone it Unfortunately, which IMO was a big mistake, this mechanism war prohibited for tagged types. ----------- * Ada's assignment is doubly dispatching. The dispatching table is a square, the diagonal of consists of thunks: Finalize (LHS); bit-copy (LHS, RHS); Adjust (LHS); Non-diagonal elements are: raise Constraint_Error; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de