--  A generic package: a bounded stack of any integer type, with its capacity as a formal
--  object; each instance is proved on its own.
generic
   type Element is range <>;
   Capacity : Positive;
package Stacks is
   type Stack is private;
   function Size (S : Stack) return Natural;
   procedure Push (S : in out Stack; X : Element)
     with Pre => Size (S) < Capacity,
          Post => Size (S) = Size (S)'Old + 1;
   function Top (S : Stack) return Element
     with Pre => Size (S) > 0;
private
   type Items is array (1 .. Capacity) of Element;
   type Stack is record
      Count : Natural := 0;
      Data : Items := (others => Element'First);
   end record
     with Type_Invariant => Stack.Count <= Capacity;
   function Size (S : Stack) return Natural is (S.Count);
end Stacks;
