4 Parameterization and Parametric Polymorphism
method
length(c@:cons['T]):int { ... }
To attach a method to a subset of the instances, a bounded implicit type variable is used as the instantiating parameter:
method
hash(c@:cons['T <= hashable]):int { ... }
If the instantiating type contains no implicit type parameter bindings, then the method is attached to a particular instance of the parameterized object:
method
detabify(c@:cons[char]):cons[char] { ... }
If multiple method implementations with the same name are defined on the same parameterized object, but with different degrees of quantification:
then the issue of which method to invoke arises. One reasonable choice would be to declare such redundant method implementations ambiguous: more than onemethod
print(c@:collection['T]):void { ... }method
print(c@:collection['T <= printable]):void { ... }method
print(c@:collection['T <= hashable]):void { ... }method
print(c@:collection[char]):void { ... }
print
method of one argument is defined for collections of characters. An alternative semantics would be to choose the most-specific matching method implementation, where a method is more specific than another if it is associated with a subset of the instances of the other. We have little experience with attaching multiple versions of the same method to different subsets of a parameterized types, so initially we have selected the more-conservative position of allowing only a single version of a method to be provided for any given instance of a parameterized type; the above declarations are illegal.
Generated with Harlequin WebMaker