I've coded C++ and grok templates. They solve some problems quite neatly, bearing in mind C++'s design focus on efficiency.
The thing you lose by having templates like the above is an explicit representation of the classes contract. You have the developer saying "<" has the same semantics in all of the classes involved - rather than it being enforced by the type system. Yes, there is no comparable interface - and that's a mistake.
So, to answer you question:
What advantage would be gained by requiring an explicit interface?
The advantage of having an explicit interface is - that you have an explicit interface :-) By saying something belongs to a particular class you are saying that it functions in a certain way, that it forfills a given contract.
I might have a class with a method set_pitch(N). If its a subclass of MusicalInstrument I know N is Hertz. If its a subclass of aircraft I know N is degrees. Statements about an objects class stop me doing the wrong thing to the wrong object.
Templates are handy in C++ but they're not really relevent to perl since it's not statically typed.
They're also not the only solution to genericity with static typing. For example, Eiffel's generic classes allow more sophisticated statements about inheritance to be made so you can say things like:
class SORTED_LIST [G -> COMPARABLE]
(you can only make SORTED_LISTs out of things that are COMPARABLE).
In reply to Re^4: OO-style modifiers for 'sub' ?
by adrianh
in thread OO-style modifiers for 'sub' ?
by Gilimanjaro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |