## Types

A type is a set of values, plus an associated set of operations valid on those values. Types are useful for catching errors ("type-checking"), documenting the programmer’s intent, and to help the compiler generate better code. Types in some languages (such as C) appear in programs, but do not exist at run-time. In such languages, all type-checking is done at compile-time. Other languages (such as standard Scheme) do not have types as such, but they have predicates, which allow you to check if a value is a member of certain sets; also, the primitive functions will check at run-time if the arguments are members of the allowed sets. Other languages, including Java and Common Lisp, provide a combination: Types may be used as specifiers to guide the compiler, but also exist as actual run-time values. In Java, for each class, there is a corresponding `java.lang.Class` run-time object, as well as an associated type (the set of values of that class, plus its sub-classes, plus `null`).

Kawa, like Java, has first-class types, that is types exist as objects you can pass around at run-time. For each Java type, there is a corresponding Kawa type (but not necessarily vice versa). It would be nice if we could represent run-time type values using `java.lang.Class` objects, but unfortunately that does not work very well. One reason is that we need to be able to refer to types and classes that do not exist yet, because we are in the processing of compiling them. Another reason is that we want to be able to distinguish between different types that are implemented using the same Java class.

Various Kawa constructs require or allow a type to be specified. Those specifications consist of type expressions, and a type expression is evaluated to yield a type value. The current Kawa compiler is rather simple-minded, and in many places only allows simple types that the compiler can evaluate at compile-time. More specifically, it only allows simple type names that map to primitive Java types or Java classes.

`type` `::=` `expression`
`opt-type-specifier` `::=` [`::` `type`]