[Next] [Previous] [Up] [Top] [Contents] [Index]

3.3 Type and Signature Declarations

3.3.7 Other Type Declarations

In addition to allowing the formals and results of methods and fields to be annotated with explicit type declarations, variable declarations and closure arguments and results can be annotated with explicit type declarations:

let_decl	::=	"let" ["var"] name [type_decl] {pragma} ":=" expr ";"
closure_expr	::=	[ "&" "(" [closure_formals] ")" [type_decl] ] "{" body "}"
closure_formal	::=	[name] [type_decl]	formal names are optional, if never referenced

If the result type of a closure is omitted, instead of defaulting to dynamic as described in section 3.4.1, the result type is inferred from the type of the result expression in the closure's body. Similarly, if the type of a constant local variable is omitted, it is inferred from the type of its initializing expression; mutable variables and global variables should be given explicit types to avoid dynamic type checking.