comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada generics
Date: Sat, 23 Dec 2006 12:43:51 +0100
Date: 2006-12-23T12:43:36+01:00	[thread overview]
Message-ID: <wvsqamnzgasf.gfemd82fzfpz$.dlg@40tude.net> (raw)
In-Reply-To: 1166805696.291429.239590@48g2000cwx.googlegroups.com

On 22 Dec 2006 08:41:36 -0800, Hyman Rosen wrote:

> Dmitry A. Kazakov wrote:
>> 1. Contract-based (this is the most important feature)
> 
> The C++ community is working on something called "concepts" which will
> be a way for templates to specify constraints on the parameters. The
> difficulty in C++ is the presence of automatic conversions and
> different overloaded operators. For example, you may have a template
> which uses "x < y" for the objects declared to be of type parameter T.
> When instantiating, there could be many ways of compiling this
> statement depending on the nature of the type parameter. It can be a
> member function of T taking one or two parameters, it can be a global
> function taking two T parameters, or it can be a function taking
> parameters not of type T but of a type to which T can be converted
> automatically. Similarly, the return type can be bool, or it can be a
> numeric type, or some object type that can be automatically converted
> to bool. Automatic type conversion is a fixed part of the C++ universe,
> and templates have to live and work within that environment.

Automatic conversions do not represent any special case. If S is
convertible to T, then S is a subtype of T, in the sense that it inherits <
from it. When S defines <, that is equivalent to overriding <. C++'s
problem is in chaotic design. There is no need in a new concept of
"concept," sorry for an unintended pun. That concept is called class = a
set of types.

> In any case, it's never been clear to me why constraints on generic
> parameters are considered to be so important by some people. Why not
> let templates be instantiated with anything the caller likes? In C++,
> if the parameters fail to satisfy some requirement in the template,
> then the compilation will fail. If the compilation succeeds, then you
> have a working instantiation. It's more likely that a constraint will
> prevent an unforeseen but valid usage from working than that it will
> catch some kind of error.

There is an even better way. It could be called "genetic programming." Let
the template generate an arbitrary code. If it compiles, it goes into
production. Customers give a feedback...(:-))

>> 3. Generic object parameters can have any type (in C++ you cannot use
>> float, for example)
> 
> Just a note on the float constraint. C++ considers instantiations
> identical if their parameters are identical, and introducing floating
> point can lead to ambiguities that the language designers chose to
> avoid by fiat. It's just the usual floating point issues, e.g., is
> 1.0/3.0*3.0 the same as 1.0? On which platforms?

Exactly. The idea of structural matching is wrong. It is uncheckable. So
what language designers do? Ada designers drop the idea and go typed. C++
designers chaotically drop some cases and some checks in an attempt to save
something that cannot be.

[ BTW, I am unhappy with anonymous access types introduced in Ada 95. It
was the C++ way. ]

>> 6. Generic instance parameters. You can pass an instance as a parameter.
> 
> C++ template parameters can themselves be template names. Is this
> something similar?

Yes, I think so.

>> 7. Generic packages (~namespaces). Anything you put in gets parametrized by
>> the formal parameters and instantiated upon the package instantiation.
> 
> In C++, classes serve the same purpose as do Ada packages, so this is
> not really a difference.

It is actually the difference between packages in Ada and classes in C++.
They are not equivalent.

>> 10. Nested generics and generic children
> 
> C++ class templates can have further class templates declared inside
> them, and class templates can inherit from other classes, so I don't
> see a difference here.

I think that 10 and 7 are in fact the same question, and any difference is
not specific to generics/templates.

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



  parent reply	other threads:[~2006-12-23 11:43 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21 14:14 Ada generics markww
2006-12-21 15:42 ` Dmitry A. Kazakov
2006-12-22  7:59   ` Martin Krischik
2006-12-22 16:14     ` Hyman Rosen
2006-12-22  7:59   ` Martin Krischik
2006-12-22 16:41   ` Hyman Rosen
2006-12-22 17:33     ` Markus E Leypold
2006-12-22 18:26       ` Hyman Rosen
2006-12-22 20:59         ` Markus E Leypold
2006-12-22 21:01           ` Markus E Leypold
2006-12-23 14:09           ` Marco
2006-12-25 14:23             ` Hyman Rosen
2006-12-29 14:13               ` Marco
2006-12-25 14:20           ` Hyman Rosen
2006-12-23 11:43     ` Dmitry A. Kazakov [this message]
2006-12-25 13:49       ` Hyman Rosen
2006-12-25 14:39         ` Dmitry A. Kazakov
2006-12-26  1:34           ` Hyman Rosen
2006-12-26  9:11             ` Dmitry A. Kazakov
2006-12-26 16:23               ` Hyman Rosen
2006-12-26 19:28                 ` Dmitry A. Kazakov
2006-12-27  1:44                   ` Hyman Rosen
2006-12-27  9:21                     ` Dmitry A. Kazakov
2006-12-27 19:06                       ` Hyman Rosen
2006-12-28 10:59                         ` Dmitry A. Kazakov
2006-12-28 16:29                           ` Hyman Rosen
2006-12-29 11:12                             ` Dmitry A. Kazakov
2006-12-29 14:56                               ` Hyman Rosen
2006-12-28 17:35                           ` Georg Bauhaus
2006-12-29 14:48                             ` Dmitry A. Kazakov
2006-12-29 19:39                               ` Georg Bauhaus
2006-12-30  9:58                                 ` Dmitry A. Kazakov
2006-12-30 14:53                                   ` Georg Bauhaus
2007-01-01 13:00                                     ` Dmitry A. Kazakov
2007-01-02 10:04                                       ` Georg Bauhaus
2007-01-02 11:11                                         ` Dmitry A. Kazakov
2007-01-02 12:33                                           ` Georg Bauhaus
2007-01-02 13:51                                             ` Dmitry A. Kazakov
2007-01-02 14:45                                               ` Georg Bauhaus
2007-01-03 10:10                                                 ` Dmitry A. Kazakov
2007-01-03 14:20                                                   ` Hyman Rosen
2007-01-03 14:55                                                   ` Georg Bauhaus
2007-01-04 10:15                                                     ` Dmitry A. Kazakov
2007-01-03 19:33                                           ` Alexander E. Kopilovich
2007-01-04 10:27                                             ` Dmitry A. Kazakov
2007-01-04 15:00                                               ` Alexander E. Kopilovich
2007-01-05 10:32                                                 ` Dmitry A. Kazakov
2006-12-30  2:25                               ` Randy Brukardt
2006-12-30 10:13                                 ` Dmitry A. Kazakov
2007-01-04  1:09                                   ` Randy Brukardt
2007-01-04 10:07                                     ` Dmitry A. Kazakov
2007-01-05  1:32                                       ` Randy Brukardt
2007-01-05  4:46                                         ` Randy Brukardt
2007-01-05  9:08                                         ` Jean-Pierre Rosen
2007-01-05 20:14                                         ` Georg Bauhaus
2007-01-06  0:14                                           ` Randy Brukardt
2006-12-29  0:09                           ` Randy Brukardt
2006-12-29 11:11                             ` Dmitry A. Kazakov
2006-12-30  2:40                               ` Randy Brukardt
2006-12-21 16:55 ` Hyman Rosen
2006-12-21 18:22   ` markww
2006-12-22  3:01 ` Steve
replies disabled

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