--  Derived types whose discriminants are not their parent's one for one: a parent
--  discriminant fixed by a value, one discriminant given to two, the order changed, and a
--  tagged type's discriminant of its own beside one that renames its parent's.
with Ada.Text_IO;
procedure Main is
   package Shapes is
      subtype Count is Natural range 0 .. 20;
      type Cells is array (Count range <>) of Integer;
      type Shape (Width, Height : Count) is tagged record
         Name : Character := 'S';
      end record;
      function Area (S : Shape) return Natural is (S.Width * S.Height);
      type Strip (Length, Depth : Count) is new Shape (Width => Length, Height => 1) with record
         Layers : Cells (1 .. Depth) := (others => 7);
      end record;
      overriding function Area (S : Strip) return Natural is (S.Length * S.Depth);
   end Shapes;
   use Shapes;

   type Grid (Rows, Columns : Count) is record
      Filled : Natural := 0;
      Data   : Cells (1 .. Columns) := (others => 0);
   end record;
   type Turned (Columns, Rows : Count) is new Grid (Rows => Rows, Columns => Columns);
   type Row (Length : Count) is new Grid (Rows => 1, Columns => Length);
   type Square (Side : Count) is new Grid (Side, Side);
   subtype Small is Count range 0 .. 5;
   type Flexible (Size : Small := 2) is new Grid (Rows => 3, Columns => Size);

   T : constant Turned := (3, 4, 5, (1, 2, 3));
   R : constant Row := (6, 7, (others => 1));
   S : constant Square := (2, 9, (8, 9));
   G : constant Grid := Grid (T);
   G2 : constant Grid := (1, 2, 0, (4, 5));
   G3 : constant Grid := (2, 2, 0, (6, 7));
   N : constant Row := (Length => 3, Filled => 1, Data => (others => 0));
   F : Flexible;
   St : constant Strip := (Length => 2, Depth => 3, Name => 'X', Layers => (1, 2, 3));
   C : constant Shape'Class := St;
   B : constant Shape := Shape (St);
begin
   Ada.Text_IO.Put_Line (T.Columns'Image & T.Rows'Image & G.Rows'Image & G.Columns'Image & G.Data (3)'Image);
   Ada.Text_IO.Put_Line (R.Length'Image & R.Filled'Image & Grid (R).Rows'Image & Row (G2).Length'Image & Square (G3).Side'Image & S.Data (2)'Image);
   Ada.Text_IO.Put_Line (N.Length'Image & " " & Boolean'Image (Row (G2) = R) & " " & Boolean'Image (Grid (Square (G3)) = G3));
   Ada.Text_IO.Put_Line (F.Size'Image & Grid (F).Rows'Image & " " & Boolean'Image (F'Constrained));
   F := (Size => 4, Filled => 2, Data => (1, 2, 3, 4));
   Ada.Text_IO.Put_Line (F.Size'Image & Grid (F).Columns'Image & F.Data (4)'Image);
   Ada.Text_IO.Put_Line (Area (C)'Image & Area (B)'Image & B.Height'Image & St.Layers (3)'Image & St.Name);
end Main;
