9.1. Discriminants - JulTob/Ada GitHub Wiki
Derived types can be parametrized with the use of discriminants.
They can also determine the type of object.
type Buffer (Length:Positive) is record
Buff:String(1..Length);
end record;
type Vehicle (IsFast: Boolean; Kind :VehicleKind) is record
FastLane: Boolean := IsFast;
case Kind is
when Car =>
Full : Boolean;
when Truck=>
Weight: Positive;
end record;
type Major_Type is (Letters, Sciences);
type Grade is delta 0.01 range 00.00 .. 10.00;
type Student (Major : Major_Type; Name_Length: Positive)
is record
Name : String(1..Name_Length);
Maths : Grade;
Philosophy: Grade;
English : Grade;
case Major is
when Letters =>
Latin : Grade;
French: Grade;
when Sciences =>
Biology : Grade;
Physics : Grade;
end case;
end record;
Discriminants cannot change during the life of the object.