Valued Types

Valued types

Valued types are the types we have seen before, the ones you define by possible values. but they have more features we should explore.

type European_Union_Countries is (
   Germany, Italy,  Greece, Spain,       --UK, -- ? --
   Ireland, Sweden, Poland, N_Macedonia
   Ukraine, Hungary, France  -- ... ETC
   );

Oh, yeah, I got political. Lough it off.

In other languages (I mean early programming languages like Algol, C, or FORTRAN), the valued types are also numeric types. They are enumerated (and are called enumeration types). I may abuse this term in Ada, even if they are not enumerated. Other languages (Pascal family) call them scalar types.

This makes no computational sense! Basically because a Bit of information is not a numeric value, but a logical one. The numeric values are given in the representation when you choose to represent these with 0 and 1 as binary digits, not just binary information unit. What we are doing here is choosing a different representation of data.

You can also define a valued type with characters.

type Even_Digits is (
   '0' , '2', '4', '6', '8'
   );

You may find that the same element can fit in two categorical types. The standard example is Orange being both a color Color'(Orange) or a fruit Fruit'(Orange) but let me show something different:

type Even_Digits is  ( '0' , '2', '4', '6', '8' );
type Prime_Digits is ( '1' , '2', '3', '5', '7' );
Prime_Digits'('2');   -- This '2' is a Prime Digit type

Even though values are not enumerated, valued types are ordered. The comparison operators function by the order of the elements on the set (which actually makes mathematical sense, in an ordered sense),

type size is  ( XXXS, XXS, XS, S, M, L, XL, XXL, XXXL );
is_smaller: Boolean := XXS < M;  
is_bigger: Boolean := XXL > M;

But maybe "<" should be read "is to the left of", not is smaller, but I chose an example where both meanings make sense (t-shirt size)