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.

Examples:

# Using the variables address, double and drawing as types 
address address_line1
def speed(double distance, time) = distance / time def draw -> drawing

Rationale: since dodo is a prototype-based language, it makes sense to allow a prototype in the place of a type in variable and function declaration.
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