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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c9629eba26884d78 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-08-07 05:28:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTED!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: <3f27bab4$1@baen1673807.greenlnk.net> <3F28F61D.4050504@noplace.com> <3F2A5303.6080902@noplace.com> <3F2BA9C8.9030700@noplace.com> Subject: Re: XML DOM Binding for Ada 95 - matter of style X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <5CrYa.421$Nf3.207@newsread4.news.pas.earthlink.net> Date: Thu, 07 Aug 2003 12:28:49 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread4.news.pas.earthlink.net 1060259329 65.110.133.134 (Thu, 07 Aug 2003 05:28:49 PDT) NNTP-Posting-Date: Thu, 07 Aug 2003 05:28:49 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:41229 Date: 2003-08-07T12:28:49+00:00 List-Id: "Georg Bauhaus" wrote in message news:bgoboh$pae$1@a1-hrz.uni-duisburg.de... > Dmitry A. Kazakov wrote: > > You don't need to know about them during the design process, > but you can construct "signature instances" like so: > > generic > type X is private; > function count(thing: X) return Natural; > procedure stretch(thing: in out X); > ... > > and then instantiate "..." with whatever actuals seem fit. This is exactly how the generic algorithms in Charles work. Something like: generic type Iterator_Type is private; with function Succ (I : Iterator_Type) return Iterator_Type is <>; with function Is_Less (L, R : Iterator_Type) return Boolean is <>; ... function Generic_O (First, Back : Iterator_Type) return Iterator_Type; There are only a few algorithms in there, because I'm still busy working on the containers. > This doesn't require that the provider of the units from which > X, count, etc. are taken, has to know beforehand that his/her types, > functions, or whatever will be used this way. To a point. But often, you design a type anticipating that that type will the used as a generic actual. For example, in Charles, all the iterator types (indeed, all the containers) have an identical interface (meaning that all the operation names are the same). This allows you pass "default" subprogram actuals, e.g. function Op is new Generic_Op (Iterator_Type); --This works because Succ and Is_Less are directly --visible at the point of instantiation. > Actually, you can pass operations of a tagged type as actuals. > Can this be done with virtual member functions in C++? Well, yes and no. You can dispatch on the operation, which would be the only point of doing it, e.g. generic type T (<>) is abstract tagged limited private; with function Op (O : in T) is <>; procedure Generic_Dispatch (O : in T'Class); procedure Generic_Dispatch (O : in T'Class) is begin Op (O); --illegal end; To do generic dispatching, you have to use a trick, um, I mean "technique," which involves passing a class-wide operation instead: generic type T (<>) is limited private; with procedure Op (O : in T) is <>; procedure Generic_Dispatch (O : in T) is begin Op (O); end; Now suppose we have a tagged type: package P is type T is tagged limited null record; procedure Op (O : T); --primitive end; Somehow we'd like to pass an object of type T'Class as a parameter to the instantion, and dispatch Op. The way to do this is create a little wrapper subprogram for Op: procedure P.Call_Op (O : in T'Class) is begin Op (O); --dispatches end; Now we have everything we need to instantiation generic op. The solution to the problem is to pass type T'Class as the generic actual type: procedure Dispatch is new Generic_Dispatch (T => T'Class, Op => Call_Op); Now when we do this: procedure Op2 (O : T'Class) is begin Dispatch (O); end; then the primitive operation Op will dispatch according to the tag of O.