with Ada.Text_IO;
procedure Main is
   package Shapes is
      subtype Small is Integer range -1000 .. 1000;
      subtype Count is Positive range 1 .. 100;
      type Base is tagged record
         V : Small := 0;
      end record;
      function Weight (X : Base) return Integer is (X.V);

      type Data is array (Positive range <>) of Integer;
      type Ext (N : Count) is new Base with record
         W : Data (1 .. N) := (others => 1);
      end record;
      overriding function Weight (X : Ext) return Integer is (X.V + X.N);

      type More (N : Count) is new Ext (N => N) with record
         Extra : Small := 5;
      end record;
      overriding function Weight (X : More) return Integer is (X.V + X.N + X.Extra);
   end Shapes;
   use Shapes;

   X : Ext (2);
   Y : constant Ext := (V => 4, N => 3, W => (7, 8, 9));
   M : constant More := (V => 1, N => 1, W => (1 => 0), Extra => 10);
   C : constant Base'Class := Y;
   B : constant Base := Base (Y);
   --  (positionally, the discriminants come first)
   P : constant Ext := (2, 30, (7, 8));
begin
   Ada.Text_IO.Put_Line (Positive'Image (X.N) & Integer'Image (X.W (2)));
   Ada.Text_IO.Put_Line (Integer'Image (Weight (C)) & Integer'Image (B.V) & Integer'Image (Y.W (3)));
   Ada.Text_IO.Put_Line (Integer'Image (Weight (Base'Class (M))) & Positive'Image (M.N) & Integer'Image (Ext (M).V));
   Ada.Text_IO.Put_Line (Positive'Image (P.N) & Integer'Image (P.V) & Integer'Image (P.W (2)));
   X.V := 6;
   Ada.Text_IO.Put_Line (Integer'Image (Weight (X)) & Integer'Image (Weight (Base (X))));
end Main;
