You can extend the fundamental types to create your own types.
The subtype statement will create a type that is compatible with the original, as if it was a renaming of the original type.
=> subtype int is integer;
In this case, "int" is equivalent to "integer" and variables of both types can be mixed freely without type casting.
Subtypes can be used where predefined types are used: you can use them to declare variables, as parameter types and as function return values.
Ada: In Ada, a subtype can be used to create a type with a smaller range of values, such as an integer with values 1 to 100. In AdaScript, the range attribute is not (yet) supported for subtypes--they are simple renamings in AdaScript.
Ada: SparForte's output subprograms (like "?", put_line, etc.) understand how to output strings and all scalar types. It work as if all necessary packages were "with"-ed and "use"-ed. In Ada, you would have to use with or instantiate I/O packages you need for each type.
A regular type is logically incompatible with the type it is extend from. To make incompatible types, create a new type with the type statement.
=> type employee_number is new integer
In this case, both types are integers. However, "employee_number" variables cannot be mixed with "customer_number" variables (or other integers) without a typecast. Use new types to make sure variables that are logically different don't accidentally mix.
Types can be used where predefined types are used: you can use them to declare variables, as parameter types and as function return values.
Ada: In Ada, a type can be used to create a type with a smaller range of values, such as an integer with values 1 to 100. In AdaScript, the range attribute is not (yet) supported for types--they are simple incompatible renamings in AdaScript.
A type derived from the same universal type as another type can converted to the other type with a type cast. You can also use a typecast to override strong typing, provided they are the same universal type underneath. To convert the type, use the name of the type with brackets around the expression you want to convert.
=> en := employee_number( cn )
You cannot cast items derived from different universal types. For example, you cannot cast a string to an integer.
=> i : integer := integer( "this is a string" )
Ada:Type qualifications are not yet implemented.
|Back To Top|