Dodo doc > Types > Use of Variables as Type

Use of Variables as Type

Type name substitution

A variable name can be used instead of a type name in declarations. The specified variable also serves as default value.

When a variable name is used as type, dodo checks the value is compatible by assignment with the specified variable.


address address_line1
double speed(double distance, time) = distance / time
drawing draw()

Rationale: this rule allows more friendly names to be used as types, notably extended variable names. Using a variable name is not exactly the same as using a type name because variable assignment follows the compatibility rules, which are different for a type and for a variable used as type.

Assignment compatibility

A variable v is compatible with variable p used as type if the following conditions are met:

This relationship is noted:

v ~ ?/p
Rationale: The compatibility rules ensure that the structure of v matches the structure of variable used as type p. As a result, v can be used where p is expected.

^ 4.7. Type Compatibility

v 4.9. Automatic Type Conversion