comp.lang.ada
 help / color / mirror / Atom feed
* Is it possible to make a possibly self-referential type using containers?
@ 2016-07-31  0:31 Shark8
  2016-07-31  2:41 ` Randy Brukardt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shark8 @ 2016-07-31  0:31 UTC (permalink / raw)


Consider something like Forth, IDL, and ASN.1 where there recursion plays a big part in the underlying ideas: the former in its definition of "Word"*, and in the latter two in the defining of types**.

So, given that the most straightforward way to implement these would be in a self-referencing type it would be nice to be able to use containers for this, perhaps like:

Type Executable_Code(<>) is private; -- The type in which we store executable code.
Type Word(<>);

Package Word_List is new Ada.Containers.Indefinite_Vectors
  (Element_Type => Word, Index_Type => Positive);

Type Word( Is_List ) is record
  case Is_List is
    when True  => List : Word_List.Vector;
    when False => Item : Executable_Code;
end record;

The above would be nicely elegant insofar as maintenance goes as it's simple and straightforward. However, we cannot use that because Element_Type cannot be a incomplete-type, but it needs to be because the full type declaration requires the instantiation of the container. -- It also seems that Limited/private with clauses cannot help. 

* Word: a chunk of code to execute or a list of words [to execute].
** Something like SEQUENCE OF INTEGER is fundamental in IDL and ASN.1.


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

end of thread, other threads:[~2016-07-31  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-31  0:31 Is it possible to make a possibly self-referential type using containers? Shark8
2016-07-31  2:41 ` Randy Brukardt
2016-07-31  5:36 ` Jeffrey R. Carter
2016-07-31  7:00 ` Dmitry A. Kazakov

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