First Class Types

FirstClassTypes refers to the ability of a programming language to treat types (howsoever defined in the language) as first-class entities - in the context of an OO language, for instance, this means that types (classes, etc.) are objects.

Quite a few languages feature FirstClassTypes, such as:

There's a draft version at --I beg to disagree with this FAQ

More below--''

*excluding lambda, which was purposely underpowered at Guido's insistence BTW.

A few other languages fake it, by introducing a type whose instances are in corresponence with the types in the language, but use/prefer alternate syntax for object creation (no "aClass new" like in Smalltalk).

And in many languages, types are not first class at all:

Languages without first-class types (or with crippled first-class types) are (roughly speaking), equivalent to the typed LambdaCalculus (and more advanced theoretical type systems in which objects and types are syntactically different entities). Languages with true first-class types are (again, roughly speaking) equivalent to the untyped LambdaCalculus (which makes no distinction). The latter form is more arguably more expressive and elegant (as a syntactic distinction is removed), but suffers from several drawbacks:


For more excitement, check out dependently typed languages (like EpigramLanguage?), where types and functions are almost exactly the same thing, and both are first class. This gets you neat features like being able to check the length of a list by its type, and .. well you can just think of the many neat things you could do if a type could be described by any amount of code. -- ShaeErisson


classes are not types, and types are not first class objects in Smalltalk, this is a matter of Smalltalk FAQ. When Dave N. Smith maintained the faq, this was mentioned explicitly. (Anybody have a copy? It seems to have disappeared from google.)

There's a draft version at The cited FAQ goes to explain how variables have no type. But Scheme (to name just one very "typeful" DynamicTypedLanguage?) has no types for variables, but it has a very defined TypeSystem. It confuses DynamicTyping vs StaticTyping. It takes this confusion further on: it says that the "claim" that classes are Smalltalk types is "an especially dangerous redefinition" of the concept of type, "from a characteristic of a variable to a characteristic of data".

Type IS a characteristic of data, as it states the way data should be interpreted. Type says "this run of bits here represent a float" and "this bytes here are a representation of a tree".

You can attach type to a variable, or data itself. If you attach it to variables, you have something like CeeLanguage.If you attach it to the data itself, you (may) have a DynamicTyping language. If you additionally pack it with operations on that data, then how is it different from classes? --fs.

Ok. Giving some more thought to it. I think classes behave for all intents like types. They:

They also: If they're still not real types, that's something you'll probably never care, anyway.


EditText of this page (last edited August 19, 2014) or FindPage with title or text search