##Value Types

[TypevaluesAliasvalsTypevalue-typesAliastypesTypeempty-typeFunconis-in-typeAliasisFunconis-valueAliasis-valFunconwhen-trueAliaswhenTypecast-to-typeAliascastTypeground-valuesAliasground-valsFunconis-equalAliasis-eq ]

###Types

Built-inTypevalue-typesAliastypes = value-typesBuilt-inTypeempty-type

`/* `

` A type ``*T*` is a value that represents a set of values.
The values of type `types` are all the types, including `types` itself.
The formula ``*V* : *T*`` holds when `*V*` is a value of type `*T*`, i.e., `*V*` is in
the set represented by the type `*T*`.
The formula ``*T*_{1} <: *T*_{2}`` holds when `*T*_{1}` is a subtype of `*T*_{2}`, i.e., the set
represented by `*T*_{1}` is a subset of the set represented by `*T*_{2}`.
The set of types forms a Boolean algebra with the following operations and
constants:
* `*T*_{1} & *T*_{2}` (meet/intersection)
* `*T*_{1} | *T*_{2}` (join/union)
* `~ *T*` (complement)
* `values` (top)
* `empty-type` (bottom)
Subtyping: ``*T*_{1} <: *T*_{2}`` is the partial order defined by the algebra.
Subsumption: If ``*V* : *T*_{1}`` and ``*T*_{1} <: *T*_{2}`` both hold, so does ``*V* : *T*_{2}``.
Indivisibility: For each value `*V*` and type `*T*`, either ``*V* : *T*`` or
``*V* : ~*T*`` holds.
Universality: ``*V* : values`` holds for all values `*V*`.
Emptiness: ``*V* : empty-type`` holds for no value `*V*`.
'Type N' declares the name 'N' to refer to a fresh value constructor
and includes it as an element of `types`.
'Type N ~> T' moreover specifies 'Rule N ~> T', so that 'N' can be used as
an abbreviation for the type term 'T'.
'Type N <: T' declares the name 'N' to refer to a fresh value constructor
in `types`, and asserts 'N <: T'.
Parametrised type declarations introduce generic (possibly dependent) types,
i.e., families of individual types, indexed by types (and by other values).
For example, `lists(*T*)` is parameterised by the type of list elements `*T*`.
Replacing a parameter by `_` denotes the union over all instances of that
parameter, e.g., `lists(_)` is the union of all types `lists(*T*)` with `*T*:types`.
Qualified variables `*V*:*T*` in terms range over values of type `*T*`.
Qualified variables ``*T*_{1}<:*T*_{2}`` in terms range over subtypes `*T*_{1}` of `*T*_{2}`.

*/Funconis-in-type(V:values,T:types) : =>booleansAliasis = is-in-type

`/*`

` `is-in-type(`*V*, *T*)` tests whether ``*V* : *T*`` holds. The value `*V*` need not be a
ground value, but `*T*` should not require testing any computation types.

*/

*Rule*

V:T------------------------------------- is-in-type(V:values,T:types) ~> trueRuleV: ~T-------------------------------------- is-in-type(V:values,T:types) ~> false

###Option types

`/*`

` For any value type ``*T*`, the elements of the option type `(*T*)^{?}` are the
elements of `*T*` together with the empty sequence `( )`, which represents
the absence of a value. Option types are a special case of sequence types.
A funcon whose result type is an option type `(*T*)^{?}` may compute a value of
type `*T*` or the empty sequence `( )`; the latter represents undefined results
of partial operations.
The parentheses in `(*T*)^{?}` and `( )` can be omitted when this does not give
rise to grouoing ambiguity. Note however that `*T*^{?}` is a meta-variable ranging
over option types, whereas `(*T*)^{?}` is the option type for the value type `*T*`.

*/Funconis-value(_:values^{?}) : =>booleansAliasis-val = is-value

`/*`

` `is-value(`*V*^{?})` tests whether the optional value `*V*^{?}` is a value or absent.

*/

Funconwhen-true(_:booleans, _:T) : =>(T)^{?}Aliaswhen = when-true

*/

Funconcast-to-type(V:values,T:types) : =>(T)^{?}Aliascast = cast-to-type

`/*`

` `cast-to-type(`*V*, *T*)` gives `*V*` if it is in `*T*`, otherwise `( )`.

*/

*Rule*

V:T------------------------------------- cast-to-type(V:values,T:types) ~>VRuleV: ~T-------------------------------------- cast-to-type(V:values,T:types) ~> ( )

###Ground values

Built-inTypeground-valuesAliasground-vals = ground-values

`/*`

```
The elements of `ground-values` are all values that are formed entirely
from value-constructors, and thus do not involve computations.
A type is a subtype of `ground-values` if and only if all its elements are
included in `ground-values`.
```

*/Funconis-equal(V:values,W:values) : =>booleansAliasis-eq = is-equal

*/

*Rule*

V==W-------------------------------------------------- is-equal(V:ground-values,W:ground-values) ~> trueRuleV=/=W--------------------------------------------------- is-equal(V:ground-values,W:ground-values) ~> falseRuleis-equal(V:~ground-values,W:values) ~> falseRuleis-equal(V:values,W:~ground-values) ~> false

`/*`

`The type `values` includes all values provided by CBS. Some funcons are declared as value constructors. Values are constructed by applying value constructor funcons to the required arguments. Values are immutable and context-independent. Their structure can be inspected using patterns formed from value constructors and variables. Computations can be extracted from values and executed, but the structure of computations cannot be inspected. Some types of values and their funcons are declared as built-in, and not further specified in CBS. New types of built-in values can be added to CBS by its developers. New algebraic datatypes may be declared by users of CBS. Their values are disjoint from built-in values.`