Signatures -- generators and observers

Instructor's Guide


intro, types, algebra, modules, classes, summary, Q/A, literature
Abstract data types may be considered as modules specifying the values and functions belonging to the type. In  [Dahl92], a type T is characterized as a tuple specifying the set of elements constituting the type T and the collection of functions related to the type T. Since constants may be regarded as zero-ary functions (having no arguments), we will speak of a signature Σ or Σ defining a particular type T. Also, in accord with common parlance, we will speak of the sorts s   ∈  Σ, which are the sorts (or types) occurring in the declaration of the functions in s   ∈  Σ. See slide 8-signature.
  
  
  
slide: Algebraic specification

A signature specifies the names and (function) profiles of the constants and functions of a data type. In general, the profile of a function is specified as f : s1 ×…×sn → s where f : s1 ×…×sn → s are the sorts defining the domain (that is the types of the arguments) of the function f, and s is the sort defining the codomain (or result type) of f. In the case n=0 the function f may be regarded as a constant. More generally, when n=0 are all unrelated to the type T being defined, we may regard f as a relative constant. Relative constants are values that are assumed to be defined in the context where the specification is being employed. The functions related to a data type T may be discriminated according to their role in defining T. We distinguish between producers g   ∈  PT , that have the type T under definition as their result type, and observers g   ∈  PT , that have T as their argument type and deliver a result of a type different from T. In other words, producer functions define how elements of T may be constructed. (In the literature one often speaks of constructors, but we avoid this term because it already has a precisely defined meaning in the object-oriented programming language C++.) In contrast, observer functions do not produce values of T, but give instead information on some particular aspect of T. The signature g   ∈  PT of a type T is uniquely defined by the union of producer functions g   ∈  PT and observer functions g   ∈  PT . Constants of type T are regarded as a subset of the producer functions g   ∈  PT defining T. Further, we require that the collection of producers is disjoint from the collection of observers for T, that is PT ∩OT = ∅.

Generators

The producer functions actually defining the values of a data type T are called the generator basis of T, or generators of T. The generators of T may be used to enumerate the elements of T, resulting in the collection of T values that is called the generator universe in  [Dahl92]. See slide 8-basis.
PT ∩OT = ∅
slide: Generators -- basis and universe

The generator universe of a type T consists of the closed (that is variable-free) terms that may be constructed using either constants or producer functions of T. As an example, consider the data type Bool with generators t and f. Obviously, the value domain of Bool, the generator universe GUBool consists only of the values t and f. As another example, consider the data type Nat (representing the natural numbers) with generator basis GNat = {0, S}, consisting of the constant 0 and the successor function GNat = {0, S} (that delivers the successor of its argument). The terms that may be constructed by GNat is the set GNat, which uniquely corresponds to the natural numbers GNat. (More precisely, the natural numbers are isomorphic with GNat.) In contrast, given a type A with element a, b, ..., the generators of GNat result in a universe that contains terms such as GNat and add(add(∅,a),a) which we would like to identify, based on our conception of a set as containing only one exemplar of a particular value. To effect this we need additional equations imposing constraints expressing what we consider as the desired shape (or normal form) of the values contained in the universe of T. However, before we look at how to extend a signature add(add(∅,a),a) defining T with equations defining the (behavioral) properties of T we will look at another example illustrating how the choice of a generator basis may affect the structure of the value domain of a data type. In the example presented in slide 8-Seq, the profiles are given of the functions that may occur in the signature specifying sequences. (The notation _ is used to indicate parameter positions.)
  
  • ε: seq T

  • _ \vartriangleright _ : seq T ×T → seq T

  • _ \vartriangleleft _ : T ×seq T → seq T

  • _ ·_ : seq T ×seq T → seq T

  • 〈 _ 〉 : T → seq T

  • 〈 _,…,_ 〉 : Tn → seq T

   - preferably one-to-one
  • Gseq T = {ε, \vartriangleright }, GUseq T = {ε, ε\vartriangleright a, ε\vartriangleright b, …, ε\vartriangleright a \vartriangleright b, …}

  • G′seq T = {ε, \vartriangleleft }, GU′seq T = {ε, a \vartriangleleft ε, b \vartriangleleft ε, …, b \vartriangleleft a \vartriangleleft ε, …}

  • G"seq T = {ε, ·, 〈 _ 〉 }, GU"seq T = {ε, 〈 a 〉 , 〈 b 〉 , ,…, ε·ε, …, ε·〈 a 〉 , …}

  
  • G"′seq T = {ε, 〈 _ 〉 , 〈 _ , _ 〉 , …}, GU"′seq T = {ε, 〈 a 〉 , 〈 b 〉 , ,…, 〈 a,a 〉 , …}


slide: The ADT Seq

Dependent on which producer functions are selected to generate the universe of T, the correspondence between the generated universe and the intended domain is either one-to-one (as for G and G′) or many-to-one (as for G′). Since we require our specification to be first-order and finite, infinite generator bases (such as G"′) must be disallowed, even if they result in a one-to-one correspondence. See  [Dahl92] for further details.