J3/99-253 Date: 11th November 1999 To: J3 From: Malcolm Cohen Subject: Unique Root Type for Extensible Types: Design 1. Introduction --------------- 1.1. Preliminary ---------------- Resolution C1 from the 1999 WG5 meeting in Cadarache adds the requirement: "add an implicit root type, from which all extensible types are extended as described in WG5-N1358". Unfortunately, WG5-N1358 is not yet available in electronic form. Therefore this paper is based on the paper copy I brought back from Cadarache. 1.2. The Requirement -------------------- WG5-N1358 covers several topics; however the relevant sections for this facility describe an implicit root type that is the root of the type inheritance tree. E.g. (example copied from N1358): Given: TYPE,EXTENDS() :: point_2d REAL x,y END TYPE TYPE,EXTENDS(point_2d) :: point_3d REAL z END TYPE TYPE,EXTENDS(point_3d) :: point_colour INTEGER colour END TYPE TYPE,EXTENDS(point_2d) :: point_radio REAL frequency END TYPE The type inheritance tree is: TYPE() | TYPE(point_2d) | +--------+--------+ | | TYPE(point_3d) TYPE(point_radio) | TYPE(point_colour) This allows us to declare polymorphic variables that cover the entire extensible type inheritance tree, e.g. (again from N1358): CLASS() :: b ! The dunamic type of B is any extensible type 1.3 Background -------------- The major reason for rejection of this approach in the beginning was that it would conflict with generic resolution; however, this has been solved by other means (essentially, eliminating potentially unsafe coercions in argument association) and so there is no longer a barrier to having a single type inheritance tree. 3. Breakdown of Functionality ----------------------------- The functionality described by paper WG5-N1358 can be broken down as follows. 3.1 Unlimited Polymorphic Variables ----------------------------------- The ability to have a polymorphic pointer, allocatable or dummy argument, that can assume any extensible type, i.e. is not limited to those types extended from a particular (named) extensible type. This is the core functionality of the proposal. 3.2 Characteristics of the Root Type ------------------------------------ The root type has no visible characteristics, i.e. it has no (public) components and no (public) type-bound procedures. (This is not specified explicitly in N1358 but is implicit). It is intrinsic in that it is provided by the system and needs no declaration. 3.3 Objects of the Root Type ---------------------------- WG5-N1358 is silent on whether it should be possible to create concrete objects of the root type. Since the root type has no characteristics it is not obviously useful to be able to create objects of that type. 3.4 Descriptive Model --------------------- The extensible type system can be described as a single type inheritance tree rooted at the intrinsic root type. 4. Proposal ----------- The only significant functionality is that provided by 3.1 (unlimited polymorphic variables). Limiting the proposal to that part of the functionality allows it to be added to the standard relatively easily. Therefore it is recommended that the ability to create concrete objects of the implicit root type not be allowed, i.e. - only polymorphic entities may be declared to be of the root type (whether we spell this CLASS() or some other way), - it shall not be possible to allocate objects of the root type i.e., we allow polymorphic dummy arguments, pointers and allocatables to be of the root type, but not ordinary local variables. With this functionality, the (normative part of the) standard itself would not contain the descriptive model above (viz the "single type inheritance tree"): however, I would envisage adding an informal description of that nature to (informative) Annex C. For full details on the proposal, see the next paper. Straw Vote: (1) proposal as described (2) allow creation and allocation of objects of the root type 5. Syntax Choices ----------------- 5.1 Declaration of a Polymorphic Entity Polymorphic entities can be declared to handle all extensible types (or equivalently, are of the implicit root type) by Straw Vote: (1) CLASS() (2) CLASS(*) (3) CLASS(ROOT) (4) ANY CLASS Remarks: CLASS() is the illustrative syntax used in WG5-N1358. I don't like it much as it looks like "class nothing" to me. CLASS(*) is the recommended option - see the next paper for details. I like it because "*" commonly matches anything... CLASS(ROOT) is pretty hard to defend, but it could be done (with considerable difficulty). ANY CLASS is easy to read but not much like our existing syntax. 5.2 Definition of an Extensible Type It has been suggested that we should revisit our syntax for defining an extensible type to take this new aspect of the type extension facility into account. When defining an extensible type, the syntax should be: Straw Vote: (1) TYPE,EXTENDS() :: new_type (2) TYPE,EXTENDS(*) :: new_type (3) TYPE,EXTENDS(ROOT) :: new_type (4) TYPE,EXTENSIBLE :: new_type Remarks: TYPE,EXTENDS() is the illustrative syntax used in WG5-N1358. I don't like it at all, as it loks like "extends nothing" which does not sound right. TYPE,EXTENSIBLE is our current syntax and therefore requires no work.