comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: limited types (Was: Records that could be arrays)
Date: Sun, 26 Feb 2006 22:07:00 GMT
Date: 2006-02-26T22:07:00+00:00	[thread overview]
Message-ID: <ulkvxbwqm.fsf@earthlink.net> (raw)
In-Reply-To: 10ovc4gxk6wka.gttjb2v0fbcq$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Sun, 26 Feb 2006 18:20:39 GMT, Matthew Heaney wrote:
> > Huh?  An Ada 2005 constructor function *is* a constructor.  It's no
> > different from a copy ctor in C++.
> 
> No. The constructor is wrapped by the function. Differently to a true
> constructor, you cannot ensure the wrapper will always be called for some
> specified signature.

This is a specious argument.  If you says the "real" constructor is wrapped by
a function then you're guilty of moving the goal-posts.

We're talking about requiring that a constructor be called. The syntax doesn't
matter.  That fact that Ada 2005 spells it f-u-n-c-t-i-o-n is irrelevent.

If you want to force a constructor to be used, then you can make the partial
view of the type indefinite.


> Consider the following use cases:
> 
> 1. Containers of class-wide types (this will be possible.)

Yes, you already have this.


> 3. Containers of specific types building a parallel types hierarchy. I.e.
> if S is a subtype of T, then a container type with the elements of S is a
> subtype of a container type with the elements of T.

You have totally misunderstood the design of the Ada 2005 container library.

When you use cursors, then this abstracts-away the container itself, leaving
you with a sequence of elements.  This model works for all the containers
already (and for arrays too, in fact).

Write your algorithms in terms of sequences of elements instead of containers,
and you can forget about containers.


> >   type ET is tagged limited private;
> >   function Copy (E : ET) return ET;  -- primitive op
> 
> This you have to override in each of non-abstract derived type. 

Not quite.  You have to override only if this is a non-null extension.  But
again that's no different from C++.  Derived classes need to implement their
own ctor, if only to call the ctor of the base class.

(In the typical case, the base class is abstract, and its ctor is declared as
protected.  The ctor available to users is the ctor of the derived class.)


> If the compiler knew that Copy is a constructor it could safely compose it
> out of constructors of the bases and the components (in most of cases.)

In practice concrete derived classes must implement their own ctors, that call
the ctor of the base class.


> >   function Copy_Classwide (E : ET'Class) return ET'Class is
> >   begin
> >     return Copy (E);  -- legal Ada 2005?
> >   end;
> 
> I don't see why it should be illegal. But I wish the compiler to do this
> automatically.

But I did this to show you how call a dispatching operation inside a generic,
with a non-tagged indefinite formal type.  

It's completely consistent with the existing generic model.  When are
operations for generic formal private types ever just synthesized?  

In the case at hand, you need an operation that takes type ET'Class, which is
the type used to instantiate the generic, so you have to write it yourself, the
same as for any other operation.


> And this is an argument? (:-))

This ignores the history of Ada language evolution:

Ada83: no function pointers; royal pain
Ada95: function pointers at library-level only: GUI callbacks, etc
Ada05: function pointers in nested scopes too

No one seems to agree with you, Dmitry!  The trend has been to allow the
declaration of "ugly" function pointers in more places, not fewer.



  reply	other threads:[~2006-02-26 22:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-24 16:51 limited types (Was: Records that could be arrays) Thierry Bernier
2006-02-24 21:57 ` Randy Brukardt
2006-02-25  2:21   ` Matthew Heaney
2006-02-25  3:38     ` Matthew Heaney
2006-02-25 11:06   ` Dmitry A. Kazakov
2006-02-25 15:05     ` Matthew Heaney
2006-02-26  1:01       ` Randy Brukardt
2006-02-26  9:00       ` Dmitry A. Kazakov
2006-02-26 18:20         ` Matthew Heaney
2006-02-26 20:52           ` Dmitry A. Kazakov
2006-02-26 22:07             ` Matthew Heaney [this message]
2006-02-27  9:11               ` Dmitry A. Kazakov
2006-02-27 14:34                 ` Georg Bauhaus
2006-02-27 16:05                   ` Dmitry A. Kazakov
2006-02-27 16:52                     ` Matthew Heaney
2006-02-27 20:21                       ` Dmitry A. Kazakov
2006-02-27 21:40                         ` Georg Bauhaus
2006-02-28  9:38                           ` Dmitry A. Kazakov
2006-02-27 23:00                         ` Matthew Heaney
2006-02-28  9:39                           ` Dmitry A. Kazakov
2006-02-28 17:24                             ` Matthew Heaney
2006-02-28 19:06                               ` Dmitry A. Kazakov
2006-02-28 19:58                                 ` Matthew Heaney
2006-02-28 21:03                                   ` Dmitry A. Kazakov
2006-02-28 21:51                                   ` limited types Simon Wright
2006-03-01  1:59                                     ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox