comp.lang.ada
 help / color / mirror / Atom feed
* Re: layering with discriminants
@ 1991-03-05 18:00 Dave Williamson
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Williamson @ 1991-03-05 18:00 UTC (permalink / raw)


In INFO-ADA Digest 91-39, David A. Hasan writes:

>GENERIC
>    TYPE size is (<>);
>PACKAGE g_lowLevel IS
>    TYPE adt (i : size) IS PRIVATE;

... lines deleted

>GENERIC
>    TYPE length is (<>);
>PACKAGE g_highLevel IS
>    TYPE adt (i : length) IS PRIVATE;
>PRIVATE
>    PACKAGE low_level IS NEW g_lowLevel(length);
>    TYPE adt (i : length) IS NEW low_level.adt(i);
>END g_highLevel;

Refer to LRM 3.7.1(3) - "A discriminant part is only allowed in the type
declaration for a record type, in a private type declaration or an incomplete
type declaration..."

I don't see anything there about derived types.  It appears that your
compiler was correct to reject, but may have led you down the garden path
with its message.

Dave Williamson
Software Kinetics Ltd.
Ottawa Ontario, Canada
williams@crc.skl.dnd.ca

^ permalink raw reply	[flat|nested] 5+ messages in thread
* layering with discriminants
@ 1991-03-02  0:28 David A. Hasan
  1991-03-04  2:52 ` Joe Hollingsworth
  1991-03-05  1:56 ` Robert I. Eachus
  0 siblings, 2 replies; 5+ messages in thread
From: David A. Hasan @ 1991-03-02  0:28 UTC (permalink / raw)


In my struggle to understand how to build layered components
in Ada, I have encountered a problem with discriminants.
Consider the following "low level" generic component:


GENERIC
   TYPE size IS (<>);
PACKAGE g_lowLevel IS
   TYPE adt (i : size) IS PRIVATE;
   -- ...other stuff...
PRIVATE
   TYPE adt (i : size) IS RECORD
    -- ...whatever...
   END RECORD;
END g_lowLevel;


Now, add a layer on top as follows:


WITH g_lowLevel;
GENERIC
   TYPE length IS (<>);
PACKAGE g_highLevel IS
   TYPE adt (i : length) IS PRIVATE;
   -- ...other stuff...
PRIVATE
   PACKAGE low_level IS NEW g_lowLevel(length);
   TYPE adt (i : length) IS NEW low_level.adt(i);   ---!!!
    -- ...whatever...
END g_highLevel;


This package might provide a different set of operations & semantics 
for its adt but implement it exactly as the lower level adt.  That's
the motivation behind what I'm doing: avoid implementing the guts of
the adt over.  This also factors the design process nicely.

My problem revolves around the fact that the DEC compiler rejects
the presence of the discriminant in the full declaration of the adt in
the private part of g_highLevel, since the declaration is not a record.
But the declaration is *derived* from a record.

My conclusion is that it is not legal to derive
types with discriminants from parents with discriminants.  
If this is true, is there anyway to achieve an equivalent effect?
--
 :   David A. Hasan
 :   WRW 402 Univ. of Texas at Austin, Austin TX 78712
 :   internet: hasan@emx.cc.utexas.edu 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1991-03-06 20:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-03-05 18:00 layering with discriminants Dave Williamson
  -- strict thread matches above, loose matches on Subject: below --
1991-03-02  0:28 David A. Hasan
1991-03-04  2:52 ` Joe Hollingsworth
1991-03-06 20:12   ` stt
1991-03-05  1:56 ` Robert I. Eachus

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