comp.lang.ada
 help / color / mirror / Atom feed
From: stt@ada-uts
Subject: Re: HELP needed!!
Date: Fri, 10-Jul-87 12:56:00 EDT	[thread overview]
Date: Fri Jul 10 12:56:00 1987
Message-ID: <57900036@ada-uts> (raw)
In-Reply-To: 322@louie.udel.EDU


A solution is to pass an access-to-A as the generic actual type,
or include an access-to-list-header as the component of B (and move
the instantiations down below the full record type definitions).

However, your best solution is probably
to define A and B as access types themselves,
and defer the whole data structure definition to the package body
(see 3.8.1:3), as follows:

    type A is private;
    type B is private;
    . . .
private
    type A_Record;  -- full definition deferred to package body
    type A is access A_Record;
    type B_Record;  -- full definition deferred to package body
    type B is access B_Record;
end pkg;

package body pkg is
    <instantiations>
    type A_Record is
       B_List : List_Of_B.List;
     . . .

This also saves you greatly on recompilations when
you decide to add or change component definitions within
A_Record or B_Record.

Tucker Taft
c/o Intermetrics, Inc.
Cambridge, MA  02138

P.S. Here is a rationale for the restrictions...

Mutually recursive types clearly require the use of
access types somewhere.  You have hidden the use
within the generic.  This conflicts with the general
rule that the legality of an instantiation
is determined by the legality of the generic itself and
the legality of the actual/formal parameter matching.
(The only error which cannot be detected until the actual
parameter substitution takes place within the spec
and body of the generic has to do with the
use of unconstrained types (see 12.3.2:4).)

Allowing uncompleted private types as actual parameters as in your
example would severely increase the number of error situations which
could only be determined upon parameter substitution.
In your example it would be illegal if a list header included an instance
of the item type directly, whereas if a list header included only
an access type, then it would be legal.

  reply	other threads:[~1987-07-10 16:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-07-07 23:57 HELP needed!! Alexander Klaiber
1987-07-10 16:56 ` stt [this message]
1987-07-14 23:41 ` Chris Henrich
replies disabled

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