The well-formedness and semantics of GEN-SPEC are essentially
as for the corresponding extension of the union of the PARAMS
specifications by body SPEC+, the only difference being that a
fitting argument has to be supplied for each declared parameter when
referencing a GEN-SPEC through its name, as explained below.
N.B. When a declared parameter is merely a SPEC-NAME, it refers
to an existing specification definition in the global
environment--it is not a local name for an argument
specification. A declared parameter, whatever its form, essentially
just specifies the signature and sentences that the body of the
generic specification may assume to be provided by the corresponding
argument specification that is supplied when referencing the generic
specification. Thus the parameter specification corresponds more to
the type of the argument than to a formal parameter name.
A fitting argument FITTING-ARG fits the argument specification
SPEC to the corresponding parameter specification via a signature
morphism SIG-MORPH. An omitted SIG-MORPH construct is taken
to be the
inclusion
morphism.
When there is more than one parameter, the fitting argument morphisms
have to be compatible, with all of them extending to a single
morphism, including moreover any fitting morphism SIG-MORPH
that is specified as a component of the enclosing
GEN-SPEC-INST. Thus any common parts of declared parameters
have to be instantiated in the same way (cf. UNION). It is
pointless to declare the same parameter twice in a generic
specification. (Generic specifications that require two similar but
independent parameters can be expressed by using a translation to
distinguish between the symbols in the signatures of the two
parameters.)
The semantics of a well-formed instantiation GEN-SPEC-INST is
the same as that of the specification determined as follows: the
fitting morphisms are extended to a single morphism applicable to the
signature of the entire generic specification GEN-SPEC named by
the GEN-SPEC-NAME, then the translation of it by this morphism
is united with all the argument specifications.
When such a compound identifier is used to name, e.g., a sort in the
body of a generic specification, the translation determined by fitting
arguments to parameters applies to the components ID+ of the
compound identifier as well. Thus instantiations with different
arguments generally give rise to different compound identifiers for
what would otherwise be the same sort, which avoids unintended
identifications when the instantiations are united.
E.g., a generic specification of sequences of arbitrary elements might
use the simple identifier Elem for a sort in the parameter, and a
compound identifier compound-id Seq Elem for the sort of
sequences in the body. Fitting various argument sorts to Elem in
different instantiations then results in distinct sorts of sequences.
Subsort embeddings between component sorts induce subsort embeddings
between the compound sorts (but not vice versa). For example, when
Nat is declared as a subsort of Int, we get automatically
(compound-id Seq Nat) embedded as a subsort of
(compound-id Seq Int)
in signatures containing all these sorts.
If there are two compound sorts with multiple components, and the
number of components are the same, and each pair of corresponding
components either consist of two identical IDs or of two sorts in the
subsort relationship, then there also is a subsort embedding between
the compound sorts.
Instantiation also behaves as expected here: if in a generic
specification we have Elem declared as a subsort of
(compound-id Seq Elem), where Elem is a parameter sort,
then in the result of instantiation of Elem by Nat, one
does get Nat automatically declared as a subsort of
(compound-id Seq Nat).
Higher-order extensions of CASL are expected to provide a more
semantic treatment of parametrized sorts, etc.
A specification definition SPEC-DEFN provides a name
SPEC-NAME for a (non-generic) specification SPEC. The
local environment given to the SPEC is empty. A
SPEC-NAME in a SPEC refers to the specification with
that name in the current global environment.
SPEC-DEFN ::= spec-defn SPEC-NAME SPEC
SPEC ::= ... | SPEC-NAME
SPEC-NAME ::= SIMPLE-ID
A specification definition GEN-SPEC-DEFN provides a name
GEN-SPEC-NAME for a generic specification GEN-SPEC. The
local environment given to the GEN-SPEC is empty. Note that a
GEN-SPEC-NAME has to be instantiated (see below) whenever it is
used in a SPEC.
GEN-SPEC-DEFN ::= gen-spec-defn GEN-SPEC-NAME GEN-SPEC
GEN-SPEC-NAME ::= SIMPLE-ID
The abstract syntax of a generic specification GEN-SPEC is
comparable to that of an EXTENSION: the parameters
PARAMS of the generic specification are extended by the list of
specifications SPEC+ that form the body.
GEN-SPEC ::= GEN-EXTENSION | GEN-CONS-EXTN
GEN-EXTENSION ::= gen-extension PARAMS SPEC+
GEN-CONS-EXTN ::= gen-cons-extn PARAMS SPEC+
PARAMS ::= params SPEC+
A generic specification instantiation GEN-SPEC-INST refers to the
generic specification named GEN-SPEC-NAME in the global
environment, providing a fitting argument FITTING-ARG for each
declared parameter (in the same order).
SPEC ::= ... | SPEC-NAME | GEN-SPEC-INST
GEN-SPEC-INST ::= gen-spec-inst GEN-SPEC-NAME FITTING-ARG+ SIG-MORPH?
FITTING-ARG ::= fitting-arg SPEC SIG-MORPH?
This extension of the syntax of identifiers for sorts, functions, and
predicates is of relevance to generic specifications. In a compound
identifier COMPOUND-ID, the components may (but need not)
themselves identify sorts, functions, or predicates that are specified
in the declared parameters of a generic specification.
ID ::= ... | COMPOUND-ID
COMPOUND-ID ::= compound-id SIMPLE-ID ID+
CoFI
Document: CASL/Summary-v0.97 --Version 0.97-- 20 May 1997.
Comments to cofi-language@brics.dk