6.2 Types and Fields

Fields can be declared to have a given type by using the %type special field in a record descriptor. The synopsis is:

%type: field_list type_name_or_description

Where field_list is a list of field names separated by commas. type_name_or_description can be either a type name which has been previously declared using %typedef, or a type description. Type names are useful when several fields are declared to be of the same type:

%typedef: Id_t    int
%type:    Id      Id_t
%type:    Product Id_t

Anonymous types can be specified by writing a type description instead of a type name. They help to avoid superfluous type declarations in the common case where a type is used by just one field. A record containing a single Id field, for example, can be defined without having to use a %typedef in the following way:

%rec: Task
%type: Id int