Prev: Lost in translation (with SPARK user rules)
Next: Sockets package in SPARK (Was: Lost in translation (with SPARK user rules))
From: Dmitry A. Kazakov on 10 Jun 2010 04:15 On Wed, 9 Jun 2010 14:22:53 -0700 (PDT), Maciej Sobczak wrote: > On 9 Cze, 16:29, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> > wrote: > >>> What is the common base class/interface for C++ or Ada containers? >> >> generic >> � �type Element is private; >> package Generic_Stack is >> � �type Stack is limited private; >> � �... >> end Generic_Stack; >> >> The common base is the [generic] interface of Stack, which all instances >> share, which every programmer has in mind talking about stack. > > Do you mean that every container supports push and pop operations > (actually Append, Last_Element, Delete_Last, etc.)? Yes. >>> How can I use it? >> >> You cannot, which is the problem of generics. > > Or maybe not generics in general, but the specific approach to > generics that was chosen by Ada. > Remember, in C++ this is not a problem: > > #include <vector> > #include <list> > > template <class ContainerOfInts> > void appendThreeInts(ContainerOfInts & c) > { > c.push_back(7); > c.push_back(42); > c.push_back(123); > } > > int main() > { > std::vector<int> vec; > std::list<int> lst; > > appendThreeInts(vec); > appendThreeInts(lst); > } > > The appendThreeInts function uses the implicit common interface, even > though vector and list do not share anything explicitly. You didn't use it. Nowhere in the program it was manifested. It appears that the program "uses" this common interface. But this "use" is as virtual as one by the hex code produced by the compiler. Similarly you could take an int variable, put there 4 and claim that the variable is even, "per use". But it is not. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Dmitry A. Kazakov on 10 Jun 2010 04:21 On Thu, 10 Jun 2010 00:36:36 -0700 (PDT), Vadim Godunko wrote: > On Jun 10, 10:54�am, Yannick Duch�ne (Hibou57) > <yannick_duch...(a)yahoo.fr> wrote: >> Le Thu, 10 Jun 2010 08:34:07 +0200, Vadim Godunko <vgodu...(a)gmail.com> a � >> �crit:> I want to known more about how to use OOP in Ada without access types! >> >> Wadim, if saying OOP, you meant dynamic dispatching, then you are indeed � >> not required to use access type for that. > No, I more asked for real example where Ada's OOP is be used without > access types in OOP way. Hmm, I never use access to tagged types except for: 1. Garbage collection 2. Mutable function arguments 3. Rosen's trick BTW, by "access types in OOP way", do you mean pointers, references or heap-allocated objects? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Yannick Duchêne (Hibou57) on 10 Jun 2010 04:44 Le Thu, 10 Jun 2010 10:07:17 +0200, Dmitry A. Kazakov <mailbox(a)dmitry-kazakov.de> a écrit: >> What would become formal parameters, like type parameters ? > > Base types, class-wide types. > >> Overloading >> functions returning type derived from that of the ancestor one ? OK. So, >> this will require an original bas type in the root definition which >> could >> be wide enough to reach actual capabilities of generics. An âANYâ type >> (like in QBasic) ? > > Nope. The element of a stack is not just any type. It is a copyable type > (the class "private" in terms of Ada generics). > >> An abstract base type ? OK. So, now, we will need to be >> able to declare abstract base type, that is, abstract discrete types, >> etc. >> Is that what's in your mind ? > > Yes. These are abstract interfaces to be defined. This is an easy part > BTW. What about ânot every thing in the same bagâ philosophy ? (many others failed in this trap) Moving generics to dynamic polymorphism... would be dynamic polymorphism where there was a kind of static polymorphism. And this is not the same from the point of view of program proof you like so much (me too, I like). Is there some kind of meta-class in you idea of a new modal ? (generics can define new types and thus can initiate new class of types, you will meta-class to achieve the same). -- There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.
From: Yannick Duchêne (Hibou57) on 10 Jun 2010 04:51 Le Thu, 10 Jun 2010 09:36:36 +0200, Vadim Godunko <vgodunko(a)gmail.com> a écrit: > No, I more asked for real example where Ada's OOP is be used without > access types in OOP way. The only known example is Tuker's work on > some part of ASIS 05, but from my point of view this work is set of > tricks and assumptions successful for concrete example but not for > general use. Depends on the reason you feel to need it. Propose a specification, we may talk about a modal. Do you need it for allocation ? Allocation is not specific to the OOP-big-bag, and dispatching does not implies memory allocation, you can use pools, etc, in Ada most of things are orthogonal you know, and using dynamic dispatching in Ada does not stick you with anything else which you may be afraid will come with. If you have an example behavior in another language you've practiced on a case similar to the one you want to drive with Ada, then let us know (so we will be more likely to understand what you have in mind). -- There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.
From: Vadim Godunko on 10 Jun 2010 04:51
On Jun 10, 12:21 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > > Hmm, I never use access to tagged types except for: > By "access types" I mean access to classwide types. > BTW, by "access types in OOP way", do you mean pointers, references or > heap-allocated objects? > I mean distinguishing of objects by instance in opposite to distinguishing by value. |