Generic Function - Comparison To Other Languages

Comparison To Other Languages

Generic functions correspond roughly to what Smalltalk calls methods, with the notable exception that, in Smalltalk, the receiver's class is the sole determinant of which body of code is actually called: the types or values of the arguments are irrelevant (single dispatch). In a programming language with multiple dispatch when a generic function is called, method dispatch occurs on the basis of all arguments, not just a single privileged one. New Flavors also provided generic functions, but only single dispatch.

Another, completely separate definition of generic function is a function that uses parametric polymorphism. This is the definition used when working with a language like OCaml. An example of a generic function is

id: a->a let id a = a

which takes an argument of any type and returns something of that same type.

Read more about this topic:  Generic Function

Famous quotes containing the words comparison and/or languages:

    I have travelled a good deal in Concord; and everywhere, in shops, and offices, and fields, the inhabitants have appeared to me to be doing penance in a thousand remarkable ways.... The twelve labors of Hercules were trifling in comparison with those which my neighbors have undertaken; for they were only twelve, and had an end; but I could never see that these men slew or captured any monster or finished any labor.
    Henry David Thoreau (1817–1862)

    It is time for dead languages to be quiet.
    Natalie Clifford Barney (1876–1972)