A type variable stands for a type within a type expression. In `List elem`, `elem` marks the element type; using the same variable for both inputs and the output of append requires all three lists to share an element type. section 1.2.5
Table 1.3. Appending typed lists, in general. Type variables describe the relationships between the inputs and outputs, even though the exact inputs and outputs are unknown. (view table figure)
| Input 1 type |
Input 2 type |
Output type |
|
|---|---|---|---|
| Simple | AnyList | AnyList | AnyList |
| Generic | List elem | List elem | List elem |
| Dependent | Vect n elem | Vect m elem | Vect (n + m) elem |
Compare simple, generic, and dependent types for appending lists: the generic signature uses `elem` to preserve the element type, while the dependent signature also tracks list lengths. section 1.2.5
In Idris, type-variable names generally begin with lowercase letters. Some type-level variables, such as `n` and `m` in dependent types, represent ordinary values and can appear in programs as well as types. section 1.2.5
Appending vectors
A signature using `Vect n elem` and `Vect m elem` describes inputs with a shared element type and lengths `n` and `m`; its output, `Vect (n + m) elem`, records both relationships. section 1.2.5
