First-class citizen
In a programming language design, a first-class citizen (also type, object, entity or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, modified, and assigned to a variable.
Definition
Robin Popplestone gave the following definition: All items have certain fundamental rights:
-
Can be the actual parameters of functions.
-
Can be returned as results of functions.
-
Can be the subject of assignment statements.
-
Can be tested for equality.
First-class function
A programming language is said to have first-class functions if it threats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures. Some programming language theorists require support for anonymous functions as well.
First-class functions are a necessity for the Functional Programming style, in which the use of higher-order functions is a standard practice. A simple example of a higher-ordered function is the map
function, which takes, as its arguments, a function and a list, and returns the list formed by applying the function to each member of the list.
Equality of functions
This question appears more difficunt and one has to distinguish between several types of function equality:
-
Extensional equality: if they agree on their outputs for all inputs.
-
Intensional equality: if they have the same “internal structure”.
-
Reference equality: functions or closures are assigned a unique identifier and equality is decided based on equality of the identifier.