next up previous

1 Overview of Fortran 90     continued...

User-Defined Types and Operators
User-defined types and operators, together with modules, give Fortran 90 an outstanding data abstraction facility and corresponding support for this aspect of object oriented programming. A user-defined type is defined with the TYPE - END TYPE construct, and objects are declared in a manner analogous to declaration of objects of intrinsic type. A simple example of a type definition and corresponding object declaration is as follows.
TYPE RATIONAL                         ! This defines the type RATIONAL.
   INTEGER :: NUMERATOR
   INTEGER :: DENOMINATOR
END TYPE RATIONAL
  ...
TYPE (RATIONAL) :: X, Y(100,100)      ! X and Y are variables of 
      ! type RATIONAL.

This might be the type defined in connection with a complete rational arithmetic data abstraction. Such an abstraction requires, in addition to the type definition, an appropriate set of operator definitions. These are done by specifying operator interfaces for user-defined functions. The following example illustrates extending the ``+" operator to addition between objects of type RATIONAL.

INTERFACE OPERATOR (+)
 FUNCTION RAT_ADD(X,Y)
  TYPE (RATIONAL) :: RAT_ADD
  TYPE (RATIONAL) :: X, Y
 END FUNCTION RAT_ADD
END INTERFACE

More details on user-defined types and operators will be discussed in sections of the next release of this chapter.