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:

    The difference between human vision and the image perceived by the faceted eye of an insect may be compared with the difference between a half-tone block made with the very finest screen and the corresponding picture as represented by the very coarse screening used in common newspaper pictorial reproduction. The same comparison holds good between the way Gogol saw things and the way average readers and average writers see things.
    Vladimir Nabokov (1899–1977)

    The less sophisticated of my forbears avoided foreigners at all costs, for the very good reason that, in their circles, speaking in tongues was commonly a prelude to snake handling. The more tolerant among us regarded foreign languages as a kind of speech impediment that could be overcome by willpower.
    Barbara Ehrenreich (b. 1941)