With this high-level granularity, it might not seem obvious how to hide the
implementation details of a type. Here is how it can be done in Ada:

package Stacks is
type Stack is private;
-- Declare a private type: You cannot depend on its
-- implementation. You can only assign and test for
-- equality.
procedure Push (S : in out Stack; Val : Integer);
procedure Pop (S : in out Stack; Val : out Integer);
private
subtype Stack_Index is Natural range 1 .. 10;
type Content_Type is array (Stack_Index) of Natural;
type Stack is record
Top : Stack_Index;
Content : Content_Type;
end record;
end Stacks;

In the above example, we define a stack type in the public part (known as the
"visible part" of the package spec in Ada), but the exact representation
of that type is private.

Then, in the private part, we define the representation of that type. We can
also declare other types that will be used as "helpers" for our main public
type. This is useful since declaring helper types is common in Ada.

A few words about terminology:

The Stack type as viewed from the public part is called the partial view of
the type. This is what clients have access to.

The Stack type as viewed from the private part or the body of the package is
called the full view of the type. This is what implementers have access to.

From the point of view of the client (the "with"ing unit), only the public
(visible) part is important, and the private part could as well not exist. It
makes it very easy to read linearly the part of the package that is important
for you.

-- No need to read the private part to use the packagepackageStacksistypeStackisprivate;procedurePush(S: inoutStack;Val: Integer);procedurePop(S: inoutStack;Val: outInteger);private...endStacks;

This is useful because, for example, for some data types the built-in assignment
operation might be incorrect (for example when a deep copy is required).

Ada does allow you to overload the comparison operators "=" and "/" for limited
types (and to override the built-in declarations for non-limited types).

Ada also allows you to implement special semantics for assignment via
controlled types. However, in some cases
assignment is simply inappropriate; one example is the File_Type from the
Ada.Text_IO package, which is declared as a limited type and thus
attempts to assign one file to another would be detected as illegal.