Type Declarations

Dylan variables may have explicit types. This allows the compiler to generate better code and to catch type-mismatch errors at compile time. To take advantage of this feature, use the :: operator:

let x :: <integer> = 2;
let vehicle :: <vehicle> = make(<car>);
let y :: <number> = 3; // any numeric class
let z :: <integer> = vehicle; // error!
      

As seen in the example, a variable may be bound to values of its declared type or to values of subclasses of its declared type. Type mismatch errors should be caught at compile time. In general, the compiler may infer the types of variables at when generating machine code. If a local variable never gets rebound to anything other than an integer, for example, the compiler can rely on this fact to optimize the resulting code.