Re: limited types (Was: Records that could be arrays)



"Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx> 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.
.



Relevant Pages

  • Re: Me vs. MyClass
    ... >| ctor. ... > the constructor as the base constructor calls it before the derived ... > I really don't see how MyClass adds or takes away support to calling ...
    (microsoft.public.dotnet.languages.vb)
  • ECMA Wrong - Class and Object Initialization Rules - Help!
    ... ECMA states in Section 1.8.1.4 on Class and Object ... Initialization Rules: ... "An object constructor shall not return unless a constructor for the base ... if a .ctor didn't invoke a base class .ctor ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Linked list problem
    ... >Now, when I try to compile this, I receive the following error: ... >C2558: struct 'TESTLIST': no copy constructor available or copy constructor ... which hasn't got an accessible copy ctor ...
    (microsoft.public.vc.language)
  • Re: Delphi 2007 Language Feature: Generics
    ... I'd be interested to know if Win32 D2007 is going to include all of the ... I think _native_ Delphi can go even further with generics than what is possible in .Net. ... In .Net, you can have a constraint, that a type parameter must have a public constructor w/o parameters. ... a default ctor in C++ just for this reason. ...
    (borland.public.delphi.non-technical)
  • Re: limited types (Was: Records that could be arrays)
    ... An Ada 2005 constructor function *is* a constructor. ... Containers of specific types building a parallel types hierarchy. ... But I wish the compiler to do this ...
    (comp.lang.ada)