What does it mean for a type T to be a "First Class" type?
In database modeling, a first class item is one that has an identity independent of any other item. The identity allows the item to persist when its attributes change, and allows other items to claim relationships with the item. As a general rule, first class items represent things rather than relationships.
A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.
Noun. first-class citizen (plural first-class citizens) A member of a class of individuals that receive fair treatment.
A first-class object is an entity within a programming language that can: Appear in an expression. Be assigned to a variable. Be used as an argument. Be returned by a function call.
Usually it means instances of T can be
Eg functions in C are not first class types as they cannot be constructed at runtime, but they are in JavaScript.
In some specialised circumstances, for example theorem proving, it means that types themselves are first class objects. More modern literature uses 'reified types' instead to denote this to avoid such ambiguity.
The use of "T" make it sound like maybe someone was speaking about the state of generics in Java (they get erased, meaning that while you can check if something is a List at runtime, you can't check if it's a List of Integer).
However, there are also "first class types," meaning that types themselves (not just instances of them) can show up anywhere, like as the value of an expression. For instance, code snippets like
someType s = new someType(); new typeOf(s); // makes a new instance of someType
But you don't see that in the wild much, since if your types depend on a value, type-checking requires more computation, and if you allow types to depend on any value, then checking becomes undecidable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With