Go backward to Structured Specifications
Go up to Structuring Constructs

Named and Generic Specifications

! SPEC-DEFN        ::=  spec-defn SPEC-NAME SPEC
  SPEC             ::=  ... | SPEC-NAME
  SPEC-NAME        ::=  SIMPLE-ID
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.

! GEN-SPEC-DEFN    ::=  gen-spec-defn GEN-SPEC-NAME GEN-SPEC
! GEN-SPEC         ::=  gen-spec CONSERVATISM? SPEC+ SPEC
! GEN-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         ::=  gen-spec CONSERVATISM? SPEC+ SPEC
The abstract syntax of a generic specification GEN-SPEC is comparable to that of an EXTENSION. The list SPEC+ gives the parameters of the generic specification, which are together extended by the body specification SPEC.

The well-formedness and semantics of GEN-SPEC are essentially as for the corresponding EXTENSION of union SPEC+ by 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.

  SPEC             ::=  ... | GEN-SPEC-INST
  GEN-SPEC-INST    ::=  gen-spec-inst GEN-SPEC-NAME FITTING-ARG+ SIG-MORPH?
  FITTING-ARG      ::=  fitting-arg SPEC SIG-MORPH?
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).

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 identity 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.

  ID               ::=  ... | COMPOUND-ID
  COMPOUND-ID      ::=  compound-id SIMPLE-ID ID+
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.

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.

In general, subsort embeddings between component sorts do not induce subsort embeddings between compound sorts. For instance, consider a specification with Nat declared as a subsort of Int. When putting together two extensions of it with sorts (compound-id List Nat), respectively (compound-id List Int), one does not get (compound-id List Nat) declared automatically as a subsort of (compound-id List Int)--this has to be specified explicitly, if required. However, instantiation 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.


CoFI Document: LanguageSummary --DRAFT, Version 0.96-- 30 April 1997.
Comments to cofi-language@brics.dk