Jump to content

Generic function

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 92.236.148.24 (talk) at 23:22, 26 June 2009 (replaced "messages" with "methods" and added cross-references. There's more work needed than I have time for.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In certain systems for object-oriented programming such as the Common Lisp Object System and Dylan, a generic function is an entity made up of all methods having the same name.

Generic functions correspond roughly to what Smalltalk calls methods; but when a generic function is called, method dispatch occurs on the basis of all arguments, not just a single privileged one. See multiple dispatch for more.

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.