Examples
In C and C++, it is not possible to create new functions at runtime, whereas other kinds of objects can. As a result, functions in C are not first-class objects; instead, they are sometimes called second-class objects, because they can still be manipulated in most of the above fashions (via function pointers). Similarly, strings are not first class objects in FORTRAN 66, because it is not possible to assign them to variables (unlike, for example, numbers).
In Smalltalk, functions (methods) are first-class objects, just like Smalltalk classes. Since Smalltalk operators (+, -, etc.) are methods, they are also first-class objects.
In many older languages (for example C) arrays were not first-class: they could not be assigned as objects or passed as a parameter to a subroutine; only their elements could be directly manipulated. Few languages support continuations and GOTO-labels as first-class objects, though arguably they don't support them as objects at all.
Concept | Description | Languages |
---|---|---|
first-class function | closures | Scheme, ML, Haskell, F Sharp |
first-class control | continuations | Scheme, ML, F Sharp |
first-class type | Coq | |
first-class data type | Generic Haskell | |
first-class polymorphism | impredicative polymorphism | |
proof object | Coq, Agda |
Read more about this topic: First-class Citizen
Famous quotes containing the word examples:
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“It is hardly to be believed how spiritual reflections when mixed with a little physics can hold peoples attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.”
—G.C. (Georg Christoph)