Dodo doc > Types > Use of Variables as Type
Use of Variables as Type
Type name substitution
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.
double speed(double distance, time) = distance / time
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.
A variable v is compatible with variable p used as type if the following conditions are met:
- Variables v and p are both based on the same prototype variable
- Variable p does not extend that prototype with new instance members
This relationship is noted:
v ~ ?/p
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