Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

  • Related entries

    No related content found.

    • Archives

    • Recent comments

    Ada: Type System

    15th March 2007

    If you didn’t read the Ada programming book I earlier recommended, then here’s the excerpt on Ada type system.

    Note: the excerpt is taken from this chapter, with copyrights belonging to respective authors.

    Here is the Ada types hierarchy (click for larger image):
    Ada types tree


    Four principles govern the type system:

    • Strong typing: types are incompatible with one another, so it is not possible to mix apples and oranges. There are, however, ways to convert between types.
    • Static typing: the programmer must declare the type of all objects, so that the compiler can check them. This is in contrast to dynamically typed languages such as Python, Smalltalk, or Lisp. Also, there is no type inference like in OCaml.
    • Abstraction: types represent the real world or the problem at hand; not how the computer represents the data internally. There are ways to specify exactly how a type must be represented at the bit level, but we will defer that discussion to another chapter.
    • Name equivalence, as opposed to structural equivalence used in most other languages. Two types are compatible if and only if they have the same name; not if they just happen to have the same size or bit representation. You can thus declare two integer types with the same ranges that are totally incompatible, or two record types with the exact same components, but which are incompatible.

    There are predefined types in the Standard package:

    • Integer, includes Natural and Positive subtypes:
      Ada integer subtypes
    • Float
    • Duration (fixed-point type specifically for timing)
    • Character (8, 16, and 32-bit)
    • String (and Wide_String)
    • Boolean

    There are also some types useful for low-level programming, defined in packages System and System.Storage_Elements.

    Share

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>