with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure strong is
f, g, flt_sum, flt_avg : Float := 0.0; -- .0 and 0. not allowed
i, j, int_sum, int_avg : Integer := 0; -- initial both?
n : Natural;
p : Positive;
begin
-- Assignment, expressions, and procedures are STRONGLY TYPED
-- Cannot mix types across assignment! None of these compile:
-- int_sum := f + g;
-- flt_sum := i + j;
-- Cannot mix types across operators! None of these compile:
-- two_pi := 2 * 3.14159;
-- int_avg := int_sum / 2.0;
-- Cannot mix types on procedure calls! None of these compile:
-- Ada.Integer_Text_IO.Put (flt_sum);
-- These are all okay.
flt_sum := f + g;
int_sum := i + j;
int_avg := int_sum / 2;
flt_avg := flt_sum / 2.0;
flt_avg := float(int_sum) / 2.0; -- EXPLICIT TYPE CONVERSION
flt_avg := float(int_sum / 2); -- Result?
-- two_pi := 2.0 * 3.14159;
-- Rules are looser with SUBTYPES. These compile:
n := 0;
i := n + 1;
-- But runtime errors can occur - where?
get(n);
i := n;
get(i);
n := i;
p := i;
p := n;
n := p;
end strong;