Generic functions provide a form of polymorphism allowing many
implementation methods with varying parameter types, called
specializers. Methods on a given generic function are chosen
according to applicability and are then ordered by specificity.
A method is applicable if each argument is an instance of each
A method A is more specific than method B
if all of A's specializers are subtypes of B's.
During method dispatch three cases can occur:
- if no methods are applicable then a no-applicable-method error
- if methods are applicable but are not orderable then an
ambiguous-method error is signaled,
- if methods are applicable and are orderable then the most
specific method is called and the next methods are established.
<gen> || (<fun>) || C |
fun-mets || (x|<gen> => <lst>) || P |
|| returns x's methods. || |
gen-add-met || (x|<gen> y|<met> => <gen>) || G |
|| adds method y to generic x. || |
ord-app-mets || (x|<gen> args|... => (tup ord|<lst> amb|<lst>)) || G |
|| returns both the list of sorted applicable methods and any ambiguous
methods when generic x is called with arguments args. || |
DG || (DG ,name ,sig) || S |
|| defines a binding with name ,name bound to a generic with signature ,sig. || |