comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Are mutually dependant and possibly recursive types using Containers possible?
Date: Fri, 9 Sep 2016 13:24:12 -0700 (PDT)
Date: 2016-09-09T13:24:12-07:00	[thread overview]
Message-ID: <d63f492e-bb6b-4861-a4a3-55c060b3d913@googlegroups.com> (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].)

             reply	other threads:[~2016-09-09 20:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-09 20:24 Shark8 [this message]
2016-09-09 20:40 ` Are mutually dependant and possibly recursive types using Containers possible? Jeffrey R. Carter
replies disabled

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