comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: GNAT GPL Edition - on the plus side
Date: Sat, 15 Oct 2005 18:14:08 +0200
Date: 2005-10-15T18:13:54+02:00	[thread overview]
Message-ID: <nczdvlj2ygm4$.1k1yb9dc4w337.dlg@40tude.net> (raw)
In-Reply-To: wcc7jcen8j0.fsf@shell01.TheWorld.com

On 15 Oct 2005 10:45:39 -0400, Robert A Duff wrote:

> "Randy Brukardt" <randy@rrsoftware.com> writes:
> 
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:b4p2ksjzkv4m.6ghazx68f8js.dlg@40tude.net...
>>> Anyway, generics and templates are inherently a mess, but that is another
>>> story. (:-))
>> 
>> Perhaps because we haven't seen any crying need. I, for one would prefer to
>> reduce the need for generics than to pile on more features.

Absolutely.

>> You have said in
>> the past that generics are unnecessary with good OOP, and I tend to agree.
> 
> Could either or both of you explain why generics are unnecessary
> (i.e. what changes to Ada's OOP would make them unnecessary).
> 
> In particular, I want to be able to have a container type tied to the
> type of its elements (perhaps class-wide).  If I have a "sequence of
> T'Class", and I put something in it, and take it back out, I don't want
> to lose the fact that this element is somewhere in the T'Class
> hierarchy.  Generics seem to work well for that.
> 
> How would you define the "sequence" abstraction without generics?

I am not sure I have understood what you meant, but it seems to me that you
want containers constrained to a particular type. I see no great problem
here. Already Ada 83 handled some constraints without any generics:

type String is ...;
subtype Punch_Card is String (1..80); -- Range constraint

We could extend this idea allowing type constraints:

type Container (...) is array (...) of Element'Class;
type Foo is new Element ...;

subtype Foo_Container is
   Container (some sugar to constrain Element'Class to Foo'Class);

As an additional advantage over generics Foo_Container can be used in all
subprograms expecting Container'Class. Otherwise, Foo_Container can be
declared as:

type Foo_Container is new
   Container (some sugar to constrain Element'Class to Foo'Class);

here "is new" has old, Ada 83 sense: create an anonymous copy of Container,
make a constrained subtype and name it Foo_Container.

[It was very unfortunate that Ada 95 used "is new" for inheritance.]

Generally, I think that in all cases when one type is composed out of some
other types (be it a record, array, access etc type) there should be a
unified language-defined way to create constrained subtypes. Maybe
explicitly via discriminants:

type Ptr (Target : T'Tag) is access T'Class (Target);
subtype Ptr_To_A is Ptr (Target => A'Tag);

Maybe implicitly assuming discriminats or attributes for constraints
everywhere.

I believe, this all is equivalent to having "type discriminants", which is
pretty close to usual intent of a programmer using generics, though on a
completely different basis.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-10-15 16:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-14  1:41 GNAT GPL Edition - on the plus side Steve
2005-10-14  4:44 ` randomm
2005-10-14 10:12   ` Alex R. Mosteo
2005-10-14 10:37     ` Martin Dowie
2005-10-19  6:06   ` jussij
2005-10-14  5:55 ` Simon Wright
2005-10-14  8:10 ` Dmitry A. Kazakov
2005-10-14  9:36   ` Martin Dowie
2005-10-14 13:13   ` Marc A. Criley
2005-10-14 17:12     ` Dmitry A. Kazakov
2005-10-14 19:05       ` Georg Bauhaus
2005-10-15  9:28         ` Dmitry A. Kazakov
2005-10-15  0:00       ` Randy Brukardt
2005-10-15 14:45         ` Robert A Duff
2005-10-15 16:14           ` Dmitry A. Kazakov [this message]
2005-10-16  0:48             ` Robert A Duff
2005-10-16  9:56               ` Dmitry A. Kazakov
2005-10-14 13:50   ` Steve
2005-10-14 17:25     ` Dmitry A. Kazakov
2005-10-14 18:58       ` Georg Bauhaus
2005-10-15  9:31         ` Dmitry A. Kazakov
2005-10-15  1:45       ` Steve
2005-10-15 11:18         ` Simon Wright
2005-10-14 17:42   ` Pascal Obry
replies disabled

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