comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Rational for not making cursor tagged in Containers
Date: Fri, 20 Apr 2007 23:28:09 +0200
Date: 2007-04-20T23:26:58+02:00	[thread overview]
Message-ID: <desawg9du795$.1nlp3h75ktl4a.dlg@40tude.net> (raw)
In-Reply-To: f0b6mm$3g0$1@jacob-sparre.dk

On Fri, 20 Apr 2007 15:11:53 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:1q1kx2jlcvnuj.ck0711mj4few$.dlg@40tude.net...
> ...
>> Also I fail to understand why polymorphic objects has to be records
>> and not arrays or access types. Why array or number cannot have
>> discriminants, but records can?
> 
> This ones easy. There is a fundamental difference between elementary types
> (which can represent only one value) and composite types (which can contain
> multiple values). Adding discriminants to an elementary type would turn it
> into a composite type -- and that way lies madness.

That's because you consider discriminant as a component. But why?
Discriminant is a constraint / parameter of a value. It is associated with
the value but is not necessarily a part of it.

Examples of discriminated scalar types:

1. type Ring_Buffer_Index (Size : Positive) is mod Size;

2. type Bounded_Integer (Min : Integer; Max : Integer) is range Min..Max;

3. type Dimensioned (Dimension : Unit) is digits 8 range -100.0..100.0;

4. type C_String (Length : Positive) is
       access all Interfaces.C.chars_array (1..Length);

Note the target is a flat array!

5. type Checked_Access (Not_Null : Boolean) is
       access not null (Not_Null) of Something;

The syntax is ugly, but I hope you got the idea.

> As far as why a polymorphic object has to be a record, that's simply because
> it is the most general composite type. It is a heterogeneous container.
> Indeed, I don't think I've ever implemented an abstraction as anything else
> (at least not for long); there is always a need for additional items beyond
> the main data.

Counter examples:

1. polymorphic access types (for smart pointers, interators, cursors) 

2, extensible enumeration types

3. polymorphic numeric types (mixed arithmetic implementations,
computations with mixed numeric representations)

> The better question is why there are arrays at all. A homogeneous container
> is by definition more limited than a heterogeneous one. So, the ideal
> language would find a way to completely unify arrays and records.

Yes, but first one should do something about static expressions. There is
no way to enforce keys of a record container to evaluate at compile-time.

> I suppose you could try to do something similar for elementary types (you
> can use special syntax if there is only one component in the container), but
> that would necessarily make programs fragile (adding a component would
> necessarily disallow that syntax, requiring massive changes).
> 
> So, I guess the ideal language would be one in which everything was a
> controlled record type. (For Janus/Ada, that's already true in many cases: a
> protected type is just a special controlled record type; task objects are
> essentially controlled, unconstrained arrays are really records that contain
> bounds and a data pointer, etc.) But such a language would be pretty
> space-inefficient (you could optimize individual calls to avoid dispatching,
> but there is no way to eliminate the space overhead, because you can never
> tell what might be done in some separately compiled unit.)

This is a consequence of IMO a wrong view on what discriminant (or tag) is.
If you consider them as components, you indeed land in the pitfall you
described above. But if discriminant is just an attribute of a value
forcibly removed when known static, then there is no any space loss. The
values of statically constrained / specific types will have no
discriminants / tags. Dynamically constrained / polymorphic values will
have it, just as dynamically constrained strings have a dope. Only the
[by-reference] types with the reserved words tagged or limited will have
discriminants and the tag among them stored the value. I think it is a
doable program.

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



  reply	other threads:[~2007-04-20 21:28 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-19 16:05 Rational for not making cursor tagged in Containers Anh Vo
2007-04-19 18:25 ` Robert A Duff
2007-04-19 19:28   ` Anh Vo
2007-04-19 20:45     ` Robert A Duff
2007-04-19 21:43       ` Dmitry A. Kazakov
2007-04-19 23:59         ` Ray Blaak
2007-04-20  7:54           ` Dmitry A. Kazakov
2007-04-20 10:56             ` Georg Bauhaus
2007-04-20 10:39               ` Dmitry A. Kazakov
2007-04-20 14:42                 ` Georg Bauhaus
2007-04-20 14:45                   ` Georg Bauhaus
2007-04-20 15:13                   ` Dmitry A. Kazakov
2007-04-20 19:37                     ` Georg Bauhaus
2007-04-20 19:32                       ` Dmitry A. Kazakov
2007-04-20 20:59                         ` Robert A Duff
2007-04-20 22:14                           ` Dmitry A. Kazakov
2007-04-23 17:38                             ` Adam Beneschan
2007-04-23 19:18                               ` Dmitry A. Kazakov
2007-04-24  0:15                                 ` Adam Beneschan
2007-04-24 10:43                                   ` Dmitry A. Kazakov
2007-04-24 16:27                                     ` Adam Beneschan
2007-04-24 20:19                                       ` Dmitry A. Kazakov
2007-04-26  0:58                                         ` Adam Beneschan
2007-04-26  7:50                                           ` Dmitry A. Kazakov
2007-04-26  8:09                                             ` Markus E Leypold
2007-04-27  8:46                                               ` Dmitry A. Kazakov
2007-04-27 11:37                                                 ` Markus E Leypold
2007-04-28 17:35                                                   ` Dmitry A. Kazakov
2007-04-29  2:31                                                     ` Randy Brukardt
2007-04-29  8:45                                                       ` Dmitry A. Kazakov
2007-04-27 20:44                                               ` Robert A Duff
2007-04-26  8:33                                             ` Markus E Leypold
2007-04-26 11:09                                               ` Markus E Leypold
2007-04-20 19:55                       ` Randy Brukardt
2007-04-22  9:54                         ` Georg Bauhaus
2007-04-22 11:19                           ` Dmitry A. Kazakov
2007-04-20 20:44                       ` Robert A Duff
2007-04-21  5:38                         ` Randy Brukardt
2007-04-22  1:14                           ` Robert A Duff
2007-04-22  4:08                             ` Randy Brukardt
2007-04-20 20:11                     ` Randy Brukardt
2007-04-20 21:28                       ` Dmitry A. Kazakov [this message]
2007-04-21  5:33                         ` Randy Brukardt
2007-04-21  9:39                           ` Dmitry A. Kazakov
2007-04-22  4:28                             ` Randy Brukardt
2007-04-22  8:38                               ` Dmitry A. Kazakov
2007-04-23 23:26                                 ` Randy Brukardt
2007-04-24 10:43                                   ` Dmitry A. Kazakov
2007-04-24  8:58                                 ` Georg Bauhaus
2007-04-24 12:21                                   ` Dmitry A. Kazakov
2007-04-21  4:48                       ` unifying arrays and records (was Re: Rational for not making cursor tagged in Containers) Ray Blaak
2007-04-20 17:05             ` Rational for not making cursor tagged in Containers Ray Blaak
2007-04-20 18:46               ` Dmitry A. Kazakov
2007-04-20 18:52                 ` Ray Blaak
2007-04-20 19:54                   ` Robert A Duff
2007-04-20  1:18         ` Anh Vo
2007-04-20  7:53           ` Dmitry A. Kazakov
2007-04-20  9:26             ` Maciej Sobczak
2007-04-20 10:15               ` Dmitry A. Kazakov
2007-04-20 11:59           ` Jean-Pierre Rosen
2007-04-20 13:23             ` Anh Vo
2007-04-20 16:02               ` Jean-Pierre Rosen
2007-04-21  2:53                 ` Anh Vo
2007-04-20  3:03   ` Randy Brukardt
2007-04-20  2:53 ` Randy Brukardt
2007-04-20 16:08   ` Anh Vo
replies disabled

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