comp.lang.ada
 help / color / mirror / Atom feed
* Are mutually dependant and possibly recursive types using Containers possible?
@ 2016-09-09 20:24 Shark8
  2016-09-09 20:40 ` Jeffrey R. Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Shark8 @ 2016-09-09 20:24 UTC (permalink / raw)


Alright, let's say we're implementing a programming a programming language  -- because the problem becomes very apparent there -- and it has a simple set of two primitive types, Real and Integer, and two complex ones, Array and String.

If it were just the primitive-types, we could use:
 Type Primitive(Is_Real : Boolean) is record
    case Is_Real is
        when True  => Real_Value    : Float;
        when False => Integer_Value : Integer;
    end case;
 end record;


We could add Strings easily enough:
 Package String_Holder is new Ada.Containers.Indefinite_Holders( String );
 
 Type Type_Indicator is ( TI_Integer, TI_Real, TI_String );
 
 Type Item( Indicator : Type_Indicator ) is record
    case Indicator is
        when TI_Integer => Integer_Value : Integer;
        when TI_Real    => Real_Value    : Float;
        when TI_String  => String_Value  : String_Holder.Holder;
    end case;
 end record;

But with adding arrays things break down:
we can't instantiate Ada.Containers.Indefinite_Vectors for use in Item because Item isn't defined at that point, yet we absolutely need it in order to make it (the structure/definition) simple.

True, we could avoid this if arrays of arrays aren't required/allowed, but the problem comes back if the language introduces/requires references and, arguably, pointers. (The difference being that the empty-holder would not be allowed in a reference, but would in a pointer [whose null value would be the no_element constant].)

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

end of thread, other threads:[~2016-09-09 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 20:24 Are mutually dependant and possibly recursive types using Containers possible? Shark8
2016-09-09 20:40 ` Jeffrey R. Carter

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