comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada generics
Date: Mon, 25 Dec 2006 15:39:03 +0100
Date: 2006-12-25T15:39:01+01:00	[thread overview]
Message-ID: <186qujlcx6rwl.1h6eq4mbdaa5s$.dlg@40tude.net> (raw)
In-Reply-To: DFQjh.1222$oo4.1118@trndny09

On Mon, 25 Dec 2006 13:49:23 GMT, Hyman Rosen wrote:

> Dmitry A. Kazakov wrote:
>> Automatic conversions do not represent any special case. If S is
>> convertible to T, then S is a subtype of T
> 
> That simply is not the case in C++. Automatic conversions do not
> define subtypes in any meaningful or useful sense. For example,
> all the numeric types automatically convert to each other. It's
> also possible to write automatic conversions between arbitrary
> classes.

Ah, but it is not required for S<:T & T<:S be wrong. Two types can be
subtypes of each other like int and float are in C. It is a common
misconception about subtypes to believe that either must not hold. Observe,
that it is wrong in Ada either. Consider this:

   type T is range 1..100;
   subtype S is T;
   procedure Exported_To_Base (X : in out S);

   X : T;
begin
   Exported_To_Base (X);  -- It is fine!

See, the operation Exported_To_Base defined on S was exported to the base
type T. In other words T inherits it from S, which is equivalent to say
that T is a subtype of S. T and S are sub-/supertypes of each other.

>> Exactly. The idea of structural matching is wrong.
> 
> It's not wrong, and it's not even structural. It is in fact
> matching by name, not by structure.

But in foo<123>, 123 is not a name. It could be in some other language
where I could do:

int 123() const
{
   return ::124; // (:-))
}

But that would make many of instantiations ambiguous.

> It's only in the case of
> constant expressions that things go a little awry. But if you
> recall the discussions we've had here on implementing units,
> it lets C++ do things that are impossible in Ada.

You mean automatic instantiation here, but I don't want it. I also don't
want this solution for this problem. I even dare say that this is a bad
solution for *any* problem. Looking a bit more deeply into the issue, there
are two things to address:

1. compile-time computations

2. types computations (types algebra)

Generics and templates offer some quite weird and limited way to have 1.
and 2. Ask yourself, is it the only way?

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



  reply	other threads:[~2006-12-25 14:39 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
2006-12-25 13:49       ` Hyman Rosen
2006-12-25 14:39         ` Dmitry A. Kazakov [this message]
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