Parameterized Implementations
Next: Classes
Up: Implementations
Previous: Stand-Alone Routine Implementations
Routine and method implementations, as well as classes, can be
parameterized. Within the scope of a parameterized implementation,
formal parameters can be used as types whose objects have only the methods
and signatures indicated in the where clause. For example, in
find [T] (x: collection[T], v: T) returns (int) signals (not_found)
where T has equal(T) returns (bool)
w: T
...
if v = w ... % short for v.equal(w)
...
end find
the call "v.equal(w)" (made using the associated short form) is legal.
Such method
calls make sense because instantiations are only permitted for types
whose objects have the required methods (3.2.2).
theta-questions@lcs.mit.edu