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

3 Static Types

3.3 Type and Signature Declarations

Variable declarations and formal arguments and results of methods, closures, and fields may be annotated with type declarations. The syntax of declarations is extended to include some new declarations:

decl	::=	let_decl
	|	tp_decl
	|	type_ext_decl
	|	object_decl
	|	obj_ext_decl
	|	predicate_decl
	|	disjoint_decl
	|	cover_decl
	|	divide_decl	
	|	signature_decl
	|	method_decl
	|	field_sig_decl
	|	field_decl
	|	precedence_decl
	|	include_decl
	|	prim_decl

In this and subsequent syntax specifications, changes to specifications as described in section 2 are in boldface.

The following example illustrates some of the extensions:

object list;
	method is_empty(l@:list):bool { l.length = 0 }
	signature length(l:list):int;
	signature do(l:list, closure:&(int):void):void;
	signature pair_do(l1:list, l2:list, closure:&(int,int):void):void;
	method prepend(x:int, l@:list):list {
		object inherits cons { head := x, tail := l } }
	method copy_reverse(l:list):list {
		let var l2:list := nil;
		do(l, &(x:int){ l2 := prepend(x, l2); };
		l2 }
representation cons isa list;
	field head(@:cons):int;
	field tail(@:cons):list;