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

4 Parameterization and Parametric Polymorphism

4.1 Explicit Parameterization

Cecil allows object, type, method, field, and signature declarations to be parameterized by a sequence of types, as the following examples illustrate:

abstract object collection[T];

abstract object list[T] isa collection[T];
	signature do[T](list[T], &(T):void):void;

concrete representation nil[T] isa list[T];

template representation cons[T] isa list[T];
	field head[T](@:cons[T]):T;
	field tail[T](@:cons[T]):list[T] := nil[T];
	method prepend[T](h:T, t:list[T]):list[T] {
		concrete object isa cons[T] { head := h, tail := t } }

abstract object table[Key,Value] isa collection[Value];

template object array[T] isa table[int,T];
	method new_array[T](size:int, initial_value:T):array[T] {
		concrete object isa array[T] {
			size := size, initial_value := initial_value } }

type printable_array[T <= printable] subtypes array[T], printable;
4.1.1 - Parameterized Declarations and Formal Type Parameters
4.1.2 - Instantiating Parameterized Declarations
4.1.3 - Parameterized Objects and Types
4.1.4 - Method Lookup
4.1.5 - Type Checking Instantiations

The Cecil Language: Specification and Rationale, Version 2.1 - 25 MARCH 1997
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker