--  Record and array types derived from untagged ones inherit their parents' primitive
--  subprograms (RM 3.4(17)): functions, procedures, a user-defined `"="` (which hides the
--  predefined one, so `B = (1, 9)` compares X only) and a function of the parent type,
--  whose result is converted to the derived type (RM 3.4(27)).
with Ada.Text_IO;
procedure Main is
   package Shapes is
      type Point is record
         X, Y : Integer := 0;
      end record;
      function Sum (P : Point) return Integer is (if P.X in -1000 .. 1000 and P.Y in -1000 .. 1000 then P.X + P.Y else 0);
      procedure Shift (P : in out Point; D : Integer) with Pre => D in -1000 .. 1000;
      function "=" (L, R : Point) return Boolean is (L.X = R.X);
      function Origin return Point is ((0, 0));
      type Vec is array (1 .. 3) of Integer;
      function First (V : Vec) return Integer is (V (1));
   end Shapes;
   package body Shapes is
      procedure Shift (P : in out Point; D : Integer) is
      begin
         if P.X in -1000 .. 1000 then
            P.X := P.X + D;
         end if;
      end Shift;
   end Shapes;
   use Shapes;
   type Place is new Point;
   type Triple is new Vec;
   A : Place := (1, 2);
   B : constant Place := (1, 5);
   T : constant Triple := (7, 8, 9);
begin
   Shift (A, 10);
   Ada.Text_IO.Put_Line (Integer'Image (Sum (A)) & Boolean'Image (A = B) & Boolean'Image (B = (1, 9)) & Integer'Image (First (T)) & Integer'Image (Sum (Place'(Origin))));
end Main;
