76 Constants
Constant declarations name pure values at component declaration scope. A constant may have an explicit declared type, or it may leave its type to be inferred from the defining expression:
const pi = 3.141592653589793;
const Real one = 1;
When no type is written, the constant's type is inferred from the expression. When a type is written, the expression must be assignable to that type, and the written type is the constant's static type. This is useful when a literal or expression could otherwise infer a narrower or less specific type than the source intends.
Constants may be parameterised with the same generic parameter syntax used by other declarations:
const Integer next<Integer N> = N + 1;
const Set<T> emptySet<Type T> = ∅;
A generic constant is referenced with an explicit generic application. This remains true when all generic parameters have defaults:
const Integer plus<Integer N = 2> = N + 1;
plus<3>
plus<>
Constants are not nullary functions. A constant reference evaluates to the named value, while a function declaration introduces an operation selected by a call expression or by a symbolic operator. Use a constant for a named value, and a function when ordinary value parameters or type-directed call resolution are part of the abstraction.