Previous section: Lexical Variables

Dylan reference manual -- Checking Types

Checking Types

Variable bindings appearing in parameter lists and in statements like let and define variable may be specialized or unspecialized. Specializing a variable indicates that the variable may only hold values of the specified type. Specialized variables have the syntax variable-name ::type . Leaving a variable unspecialized indicates that it may hold values of any type. Unspecialized variables simply appear as variable-name.

Each type is any expression that evaluates to a valid Dylan type (that is, an instance of <type>). The types are evaluated before the init, in the same environment as init. Each type specifies the type of the corresponding variable. Attempts to initialize or assign the variable to a value which is not an instance of the corresponding type results in a type error being signalled.

? begin
    let x :: <integer> = sqrt (2);
    x
  end
error: 1.4142135623730951 is not an instance of <integer>
? define variable foo :: <integer> = 10;
foo
? foo := sqrt (2)
10
error: 1.4142135623730951 is not an instance of <integer>

Next section: Binding Multiple Values