For fields without type annotations, their type defaults to any(). That is, the previous example is a shorthand for the following:
- -record(rec, {field1 :: Type1, field2 :: any(), field3 :: Type3}).
In the presence of initial values for fields, the type must be declared after the initialization, as follows:
Note
Before Erlang/OTP 19, for fields without initial values, the singleton type 'undefined' was added to all declared types. In other words, the following two record declarations had identical effects:
- -record(rec, {f1 = 42 :: integer(),
- f3 :: 'a' | 'b'}).
- f2 :: 'undefined' | float(),
- f3 :: 'undefined' | 'a' | 'b'}).
Any record, containing type information or not, once defined, can be used as a type using the following syntax:
In addition, the record fields can be further specified when using a record type by adding type information about the field as follows: