comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Re: derived formal types and known discriminants
Date: Thu, 29 Jun 2017 07:15:05 -0700 (PDT)
Date: 2017-06-29T07:15:05-07:00	[thread overview]
Message-ID: <82a59ee9-8d55-4c73-9daf-e9f7d9ab8a8f@googlegroups.com> (raw)
In-Reply-To: <oijivk$m72$1@franka.jacob-sparre.dk>

On Friday, June 23, 2017 at 1:26:12 PM UTC-4, Randy Brukardt wrote:
>
> I don't know, I can only guess. And my guess would be that discriminants 
> that are added/removed would be a problem. Within the generic, you could 
> declare objects giving those discriminant values, but they might not be 
> right. For a type with unknown discriminants, you can't declare an object at 
> all, so that's easier.
> 
> But why using the same matching rules used for formal private types wouldn't 
> work, I don't know. Or maybe it just didn't seem worth worrying about, given 
> that formal derived types are mainly useful to give Steve Baird a rare 
> mechanism for the amazing semantic issues that he comes up with. (Yes, 
> formal tagged derived types have some uses in deep type hierarchies, and 
> that's about it, because no one declares other kinds of derived types in the 
> first place.)
> 
>                                       Randy.


You imply that the feature is little-used, but isn't this (one of) the primary mechanisms for MI via the so-called "mixin"?  In Mr. Taft's paper from 1994 ("Multiple Inheritance in Ada 9X"), he lists the three common cases, of which #2 is the "generic with a formal derived type" method, i.e. instead of having C extend both A and B, you make one of the parents a generic that extends a formal derived type of the other, and than have the child and extend that.  But if I understand it (quite likely not the case...), this effectively limits this method to parent types without discriminants?

For example, suppose I have the abstract type A with some arbitrary discriminants, and I extend it into two concrete types Ax and Ay; each has the option to either inherit the parents discriminants outright, or replace them with their own set (constraining the parent as needed).  Now suppose I wish to extend Ax and Ay into Bx and By, respectively, but also extend them from an unrelated abstract type W with it's own arbitrary discriminants.  I arrange W into a generic package with a formal type derived from A, with the intent of instantiating it twice (once on Ax and once on Ay), and then extending each of those to create Bx and By, thus giving me everything from A and W together.

But now I appear to be stuck, since there's no way to give W discriminants; doing so requires constraining the discriminants of the formal type, which I have no visibility into, since they are unknown.  Consequently, I just have to inherit the parents discriminants as-is, and none of the functionality of W can depend on them.  If, however, there was the ability to have a known_formal_part on the formal derived type, I could at least do this in situations where the actuals (Ax and Ay) had consistent numbers/types of discriminants, e.g. "T is a type extended from A with one Integer discriminant 'D'", and so W could extend T by constraining D.

Am I understanding all this correctly? Or are there perhaps other ways of doing this I am overlooking?  I admittedly just starting to delve into Ada's whole 'mix-in' approach, so please set me straight if i'm trying to put a round peg into a square hole.

Thank you again for your responses.

-sb


  reply	other threads:[~2017-06-29 14:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23  0:45 derived formal types and known discriminants sbelmont700
2017-06-23 17:26 ` Randy Brukardt
2017-06-29 14:15   ` sbelmont700 [this message]
2017-06-29 14:39     ` Dmitry A. Kazakov
2017-06-29 17:40       ` Robert Eachus
2017-06-30  1:10     ` Randy Brukardt
2017-06-30  7:24       ` Dmitry A. Kazakov
2017-06-30 18:09         ` Randy Brukardt
2017-07-04  0:30           ` sbelmont700
2017-07-04  1:36             ` gautier_niouzes
2017-07-04  2:29             ` Randy Brukardt
2017-07-04  7:09             ` Dmitry A. Kazakov
2017-07-04 17:34               ` Shark8
2017-07-03 17:24 ` Jere
replies disabled

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