Making a specification generic (when appropriate) improves its reusability.
As mentioned in the previous chapter, naming specifications is a good idea. In many cases, however, datatypes are naturally generic, having sorts, operations, and/or predicates that are deliberately left loosely specified, to be determined when the datatype is used. For instance, datatypes of lists and sets are generic regarding the sort of elements. Generic specifications allow the genericity of a datatype to be made explicit by declaring parameters when the specification is named: in the case of lists and sets, there is a single parameter that simply declares the sort Elem. A fitting argument specification has to be provided for each parameter of a generic specification whenever it is referenced; this is called instantiation of the generic specification.
The aim of this chapter is to discuss and illustrate how to define generic specifications and instantiate them. We have seen plenty of simple examples of generic specifications and instantiations in the previous chapters. In more complicated cases, however, explicit fitting symbol maps may be required to determine the exact relationship between parameters and arguments in instantiations, and so-called imports should be separated from the bodies of generic specifications.
- Total Order
- List Length
- Predicate Symbol
- Operation Symbol
- Integer Arithmetic
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.