Derived Type Definition
Standard: F77 F90 F95 F2003 F2008
  Example Program
    [ type-param-def-stmt ]...
    [ private-or-sequence ]...
    [ component-defn-stmt ]...
    [ PRIVATE ]
    [ type-bound-proc-stmt ]... ]

END TYPE [ type-name ]

type-param-def-stmt ::= integer-type , type-param-attr :: type-param-decl-list
integer-type ::= INTEGER [ ( [ KIND = ] expr ) ]
type-param-attr ::= KIND | LEN
type-param-decl-list ::= type-param-decl [ , type-param-decl ]...
type-param-decl ::= type-param-name [ = expr ]

private-or-sequence ::= PRIVATE  |  SEQUENCE

The CONTAINS part shall not appear in a BIND(C) or SEQUENCE type.

type-bound-proc-stmt ::= specific-tbp-stmt  |  generic-tbp-stmt  |  final-procedure-stmt

The basic syntax of the statements in the type-bound procedure section is as follows.

generic-tbp-stmt ::= GENERIC [ , access ] :: generic-spec => type-bound-procedure-name-list
specific-tbp-stmt ::= PROCEDURE [ ( interface-name ) ] , type-bound-attr-list :: binding-list
final-procedure-stmt ::= FINAL [ :: ] final-subroutine-name-list

Refer to the pages on type-bound procedures and the FINAL statement for full syntax and semantics.
A derived type definition defines a derived type.

If it contains the SEQUENCE statement it is a sequence derived type; objects of such a type may appear in COMMON and EQUIVALENCE. Two sequence derived types are the same if they have the same name, their components have the same names and appear in the same order, and corresponding components have the same type, rank, and attributes.

If the component part of the type definition contains the PRIVATE statement, the default accessibility of each component is PRIVATE. In Fortran 2003, this can be overridden by explicit declaration in each component definition statement. It is not permitted to give a private component a value in a structure constructor for the type when outside the module; normally this makes the structure constructor unavailable, but it can be used if the component has “default initialisation” because in that case the value for the component may be omitted in the constructor.

In Fortran 2003, a type can have a type-bound procedure part. This part defines type-bound procedures, which are procedures that are bound to the type itself and are accessible via objects of the type. The default accessibility of type-bound procedures is PUBLIC unless the type-bound procedure part contains a PRIVATE statement, even if the default accessibility of components is PRIVATE.

In Fortran 2003, a type can have type parameters. Each type parameter must be listed on the TYPE statement and be declared by a type-param-def-stmt. A type parameter is either a KIND type parameter or a LEN type parameter. If the type parameter is given a value in its declaration, this is its default value; a type parameter with a default value can be omitted from a declaration or structure constructor.

A KIND type parameter is permitted to appear in any expression inside the type definition, including within constant expressions; when declaring an entity of the type, the value supplied for a KIND type parameter must be a constant expression. A LEN type parameter is only permitted to appear within the type definition in an array bound, character length, or an expression supplied for a LEN type parameter (of a component); when declaring an entity of the type, the value supplied for a LEN type parameter can be a colon (“deferred” — only if the entity has the ALLOCATABLE or POINTER attribute), an asterisk (“assumed” — only if the entity is a dummy argument), or an expression (possibly non-constant).
BIND attribute, Component Definition statement, END TYPE statement, EXTENDS clause, FINAL statement, PRIVATE attribute, PUBLIC attribute, SEQUENCE statement, TYPE statement, Type-bound procedure