J3/99-255 Date: 15th November 1999 To: J3 From: Malcolm Cohen Subject: Generalised Structure Constructors 1. Introduction Resolution C1 from the 1999 WG5 meeting in Cadarache adds the requirement: "add the generalization of structure constructors, as described in WG5-N1355". WG5-N1355 has been electronically available for some time (as a WG5 paper, not a J3 paper). This paper is based on N1355, though an attempt has been made to make it self-contained. 2. Requirement >From WG5-N1355: "Users should be permitted to override the intrinsic data-type structure constructor by the creation of procedures with a generic name that is the same as the type-name. The same rules should be applied, mutatis mutandis, as already exist for overriding intrinsic definitions for the semantics of intrinsic assignment and intrinsic functions by user written generic procedures. ... Although this proposal will not in general allow the creation of user defined derived type objects with the PARAMETER attribute, nor will it make initialisation more generally supportable. It will, however, allow appropriately named user-defined type-conversion procedures to be used to create values of derived types. For example, given a type definition for variable precision arithmetic based on a type, TYPE NUMBER INTEGER::exp INTEGER,POINTER::sig(:) END TYPE NUMBER The user could define additional generic procedures called NUMBER. One specific version could take a single integer argument and another could take a character string argument; both designed to return a value of the NUMBER datatype. This will allow the following set of statements to be valid. type(NUMBER)::ten,c ten=NUMBER(10) c=NUMBER("2.99792458E+8") With a data type such as this the user has no simple way of using the intrinsic value constructors to create the structure values. Usable values can only be created by procedures written by the user to provide a more appropriate type conversion. In general, the logical name for such conversion procedures is the typename. In this example the name NUMBER is the appropriate. This minor change provides a valuable regularisation and aid to program readability and does not preclude the later addition of more extensive constructor functionality." 3. Specifications Type names shall be treated similar to generic function names for the purpose of scoping. The intrinsic structure constructor (if available) shall participate in the resulting generic resolution. The characteristics of the intrinsic structure constructor as a generic function shall be those which provide the same syntax for the existing reference; note that components with default initialisation behave like optional dummy arguments. The intrinsic structure constructor may be overridden by a procedure which has the same characteristics as it appears to have; in that way it behaves similarly to intrinsic functions. 4. Syntax Additional procedures may be given the same generic name as a type name by an INTERFACE block, just as if the type name were a generic name. 5. Edits To be added.