Whirlwind Tour of Ada - Part 2b - More on Types

A Rich Type Model

A Rich Type Model



Types and Subtypes

What is a Subtype

Declaring Subtypes in Ada

Why Do We Use Subtype Natural?

Mixing Types and Subtypes

Subtypes Example: Type Checking, Constraint Error

Subtypes: Implicit Conversion

Numeric Subtypes and Java

Class Subtypes and Java

Subtypes and Strong Typing

  1. Strong type checking at compile time: Compiler verifies that operations operate on valid variables
  2.         myFloat: float := 3;   -- invalid
            myVar := 2 + 3.0;      -- invalid
  3. Compiler generates runtime checks to verify variables are assigned only valid values
  4.             get(myNat);        -- needs runtime check
                myPos := myNat;    -- needs runtime check

Other Ways of Creating Types

Other Ways of Creating New Types

New Numeric Types

Defining New Numeric Types

Modular Types

Floating Point Types

Decimal Fixed Point Types

Fixed Point and Decimal Fixed Point Types

Enumerated Types

Enumerated Types

Enumerated Types