From: Shark8 <onewingedshark@gmail.com>
Subject: Is it possible to make a possibly self-referential type using containers?
Date: Sat, 30 Jul 2016 17:31:02 -0700 (PDT)
Date: 2016-07-30T17:31:02-07:00 [thread overview]
Message-ID: <18dfc647-ef22-4052-b6ad-ce3516124085@googlegroups.com> (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.
next reply other threads:[~2016-07-31 0:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-31 0:31 Shark8 [this message]
2016-07-31 2:41 ` Is it possible to make a possibly self-referential type using containers? Randy Brukardt
2016-07-31 5:36 ` Jeffrey R. Carter
2016-07-31 7:00 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox