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,b553d2c02a2df59f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!txtfeed2.tudelft.nl!tudelft.nl!txtfeed1.tudelft.nl!feeder3.cambrium.nl!feed.tweaknews.nl!195.14.215.230.MISMATCH!news.netcologne.de!nhp.netcologne.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: limited types (Was: Records that could be arrays) 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: <1cwl2r5h594du$.1q4kglbpb2bma.dlg@40tude.net> <10ovc4gxk6wka.gttjb2v0fbcq$.dlg@40tude.net> <13yslifejxwuq.15rip8gh2aufj.dlg@40tude.net> <44031ace$0$13779$9b4e6d93@newsread4.arcor-online.net> <1i6nwodxgp1bn.voklt7nvcl1g$.dlg@40tude.net> <1141059143.617291.39980@i40g2000cwc.googlegroups.com> <1dd53t0syyc1z.1ety6xoat1ce5$.dlg@40tude.net> <44037195$0$13798$9b4e6d93@newsread4.arcor-online.net> Date: Tue, 28 Feb 2006 10:38:31 +0100 Message-ID: <6pmoa2lmyfty.i9e0ddc3no7p$.dlg@40tude.net> NNTP-Posting-Date: 28 Feb 2006 10:38:35 MET NNTP-Posting-Host: b2cf02c6.newsread4.arcor-online.net X-Trace: DXC=IFRi\bQn9SnCUhGd:LVK2e:ejgIfPPlddjW\KbG]kaMhQc4L4[MA2T`@OSh4R9@6kb[6LHn;2LCVn7enW;^6ZC`dIXm65S@:3>o X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:3198 Date: 2006-02-28T10:38:35+01:00 List-Id: On Mon, 27 Feb 2006 22:40:18 +0100, Georg Bauhaus wrote: > Dmitry A. Kazakov wrote: > >> The question Georg asked was: where typed containers of elements of related >> types might themselves appear related. The number of cases is huge. >> Generics fundamentally cannot help here, they aren't dynamically >> polymorphic. > > But then wouldn't you again be mixing apples and herrings? > > type APPLE_CONTAINER is new CONTAINER with null record; > -- specializes in apples, only > > type HERRING_CONTAINER is new CONTAINER with null record; > -- specializes in herrings, only > > x: access CONTAINER'class := ...; > > x.insert(an_apple); -- right or wrong? compile time? You cannot tell without the contract of Container. The above could be compile error, run-time error or correct. There are three [all useful] variants: 1. Containers of related types are unrelated 2. Containers of related types are same 3. Containers of subtypes are subtypes (polymorphic containers) [there is also an axis for the container index/cursor types] The variants 1 and 2 are relatively easy to get. The variant 3 is much more challenging. Consider [imaginary syntax]: type Food is ... type Food_Container is ..; -- of Food'Class type Apple is new Food with ...; type Herring is new Food with ...; type Apple_Box is new Food_Container (Element'Tag => Apple'Class); type Herring_Barrel is new Food_Container (Element'Tag => Herring'Class); X : Food_Container'Class := Some_Herring_Barrel; Y : Herring_Barrel := Some_Herring_Barrel; X.Insert (An_Apple); -- Constraint_Error at run-time Y.Insert (An_Apple); -- Constraint_Error at run-time + compiler warning With full ADT one could also do this type Apple_Only_Box is new Food_Container some syntax sugar; private type Apple_Only_Box is array (...) of Apple; -- The implementation of the container is completely overridden -- and replaced by a more efficient > In fact, herrings with little pieces of apple aren't > that unusual, add onions and mayonnaise and you are > almost set - rather pickled red beets and cucumbers ... > not everyone's taste, maybe. :-) Not in a class of apple juice! (:-)) > Seriously, > wouldn't type-forcing containers be in the way of > composition? It will, when that is what's needed. It should be programmer's choice. And it is much more flexible that the choices we have now: either same type or different types. Ada was always better than that. Consider Integer and Positive as an example. Now what about an array of Integers vs. an array of Positives. Then a slice of an array of Positives. Presently, constraints cannot propagate between types. This is a weakness of the type system. You cannot get an array subtype by constraining its elements. You cannot get an access subtype by constraining the target type. This is more general and important question than just container types. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de