Generic Component: Views
A simple generic component such as sum involves several types,
mappings, and a constant:
- Tacc, accumulator type. sum is defined for any type
that defines a + operator, including integer, real,
boolean, string, and any application type that
- Constant C0:Tacc, initial value of the accumulator.
C0 defaults to the zero value of the type Tacc;
it is possible to specify a sum with a non-zero initial value
(e.g. a taxi meter).
- Trec, accumulator record type. A component such as
sum never ``owns'' its storage; instead, the storage is owned
by some outside component and passed to sum as a parameter.
- A mapping Macc: Trec &rarr Tacc that
specifies how to obtain the data for this instance of sum
from data of type Trec. This mapping must allow both reading
and writing of the accumulator value. There could be multiple
instances of sum data in a Trec, e.g., it might be
desired to sum both cost and shipping weight at the same time.