comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Distilled by Richard Riehle
Date: Sat, 28 Jul 2018 00:16:08 +0200
Date: 2018-07-28T00:16:08+02:00	[thread overview]
Message-ID: <pjg5j6$11hv$1@gioia.aioe.org> (raw)
In-Reply-To: d89a34f0-3a49-41d2-9d3d-8e85fe26bea8@googlegroups.com

On 2018-07-27 23:34, Shark8 wrote:
> On Friday, July 27, 2018 at 2:07:21 PM UTC-6, Dmitry A. Kazakov wrote:
>>
>> Types algebra, yes. Most important type operations Ada lacks are:
>>
>> - ad-hoc supertypes,
>> - interface inheritance,
>> - full MI,
>> - full MD
> 
> Ad-hoc supertypes are, I think, a mistake. The value in SUBTYPE is that it is a singular set of restrictions [possibly null] placed upon it's "supertype". What this means is that for every SUBTYPE S there's an application of 'Base to get to the first subtype (Ada "TYPE") -- This means that the relation of TYPE/SUBTYPE can be graphed as a tree; if we introduce ad-hoc supertypes, we lose this property and now have to contend with a full many-to-many possibility TYPE-network rather than TYPE-tree.

No, we don't lose anything. It is only about the order of declarations. 
Supertype can be declared after is child:

    def A
    def B <: A

vs.

    def B
    def A :> B

The topology of type relationships is same.

> And I fail to see how this would be useful in-practice. (IOW, what is the real use-case? Does that use-case justify such an increase in complexity?)

You could inject interfaces into existing types by creating their 
adoptive parents. E.g. create a descendant of Root_Stream_Type which is 
an ad-hoc supertype of String, and here is you streaming into/from strings.

You can create classes of equivalent types, e.g. resolving messy design. 
Consider Unbounded_String and String. You create

1. a descendant of String which is an ad-hoc parent of Unbounded_String. 
Now any operation of String applies to Unbounded_String.

2. a descendant of Unbounded_String which is an ad-hoc parent of String. 
Now any operation of Unbounded_String applies to String.

It almost always a combination of a super and subtype (in non-Ada sense):

    A <: ad-hoc glue type <: B

To create a relation between two totally unrelated existing types A and B.

> I'm in agreement with interface-inheritance, I think: IIRC, you're referring to what is essentially my idea for "abstract interfaces" whereby we could define Ada's type-system in terms of the stated hierarchy; as per this picture:  https://en.wikibooks.org/wiki/Ada_Programming/Type_System#The_Type_Hierarchy -- exposing what is already fairly explicit in the LRM.

Yes, you could formally describe such hierarchies because you would not 
inherit representations and thus could bring let differently implemented 
types to participate in a class and have class-wide objects of that class.

> Multiple Inheritance -- I'm not sure this is a good idea at all. Looking at C++ programmers and their experiences it seems to be more trouble than it's actually worth. (Interfaces aren't so bad, but can still conflict; Delphi has the IMPLEMENTS keyword that can be used for both disambiguation as well as delegation.) ...Why do you think Ada (or its successor) should have full MI?

Because it desperately needed in practical work.

In my actual project it could possibly reduce the code size tenfold. 
MI's code reuse is emulated per interfaces passed as parameters to 
generics. This leads to a huge  explosion of compilation units, just 
because I cannot inherit bodies of operations from the interfaces, which 
must be interfaces and cannot be abstract types. Instead of

    type A is abstract ...
    procedure FA (X : in out A);

    type B is abstract ...
    procedure FB (X : in out B);

    type C is new A and B ...;

You must stuff "inherited" bodies into a generic to be added to whatever 
descendant type:

    type A_Interface is abstract ...
    procedure FA (X : in out A) is abstract;

    type B_Interface is abstract ...
    procedure FB (X : in out B) is abstract;

    generic
       type Base_Type is new A_Interface and B_Interface ...
    package Standing_On_The_Head is
       type C is new Base_Type with ...;
       overriding procedure FA (X : in out C);
       overriding procedure FB (X : in out C);
    end Standing_On_The_Head;

If you have several lines of inheritance this gives you a ballistic 
combinatorial explosion of generic instances.

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

  reply	other threads:[~2018-07-27 22:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-15 18:09 Ada Distilled by Richard Riehle rabbibotton
2018-07-16  1:02 ` Shark8
2018-07-21  6:07   ` Randy Brukardt
2018-07-26  0:42     ` rabbibotton
2018-07-26 20:17       ` Shark8
2018-07-26 21:10         ` Jeffrey R. Carter
2018-07-27  3:01           ` Paul Rubin
2018-07-27 14:32           ` rabbibotton
2018-07-27 20:18             ` Paul Rubin
2018-07-27 17:02           ` Shark8
2018-07-27 14:30         ` rabbibotton
2018-07-27 17:11           ` Shark8
2018-07-27 18:52             ` Dan'l Miller
2018-07-27 20:07               ` Dmitry A. Kazakov
2018-07-27 20:38                 ` Dan'l Miller
2018-07-27 21:32                   ` Dmitry A. Kazakov
2018-07-28  2:41                     ` Dan'l Miller
2018-07-28  7:10                       ` Dmitry A. Kazakov
2018-07-28 15:01                         ` Dan'l Miller
2018-07-28 15:41                           ` Dmitry A. Kazakov
2018-07-28 16:05                             ` Dan'l Miller
2018-08-06 19:33                             ` Vincent
2018-08-06 22:01                               ` Dmitry A. Kazakov
2021-12-09 11:13                                 ` Kevin Chadwick
2018-07-27 21:34                 ` Shark8
2018-07-27 22:16                   ` Dmitry A. Kazakov [this message]
2018-07-28  3:52                 ` Dan'l Miller
2018-07-28  7:12                   ` Dmitry A. Kazakov
2018-07-27 20:35               ` Paul Rubin
replies disabled

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