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

4.3 Matching Against Type Patterns

4.3.6 Matching and Bounded Formal Type Parameters

When instantiating a parameterized type with a binding occurrence of an implicit type parameter, any upper bounds specified at the declaration of the parameterized type are inherited automatically by the bound type variable. For example, hash tables can require that their keys must be hashable:

template object hash_table[Key <= hashable, Value] isa collection[Value];
Methods defined on hash tables can bind type parameters to the types of the keys and values of the table:

method fetch(t@:hash_table['Key,'Value], key:Key):Value { ... }
Since all hash tables must take hashable keys, when type checking the body of the fetch method, the type checker can assume that the Key type variable is a subtype of hashable.


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

Generated with Harlequin WebMaker