09-266 To: J3 From: Malcolm Cohen Subject: Interp F03/0090 Date: 2009 July 27 1. Introduction This paper contains a revised answer to F03/0090. 2. Interpretation request ---------------------------------------------------------------------- NUMBER: F03/0090 TITLE: Polymorphic array constructors KEYWORDS: polymorphic, array constructor DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: (1) Consider FUNCTION f1(dummy,n) CLASS(t) dummy TYPE(t) f(n) f = [ (dummy,i=1,n) ] END FUNCTION Is this standard-conforming? (2) If the array constructor elements are polymorphic, is the array constructor polymorphic with the dynamic type of the elements? For example, consider FUNCTION f2(dummy,n) CLASS(t) dummy CLASS(t),ALLOCATABLE :: f(:) IF (...) THEN ALLOCATE(f(n),SOURCE=[(dummy,i=1,n)]) ! **1 ELSE ALLOCATE(f(n),SOURCE=dummy) ! **2 END IF END FUNCTION The second ALLOCATE statement (marked **2) clearly allocates F with size N and the dynamic type of DUMMY. If the array constructor is polymorphic, the first ALLOCATE statement (marked **1) will have the same effect, otherwise it will allocate F with the dynamic type of F equal to the declared type of DUMMY. (3) If the array constructor is polymorphic, what is the dynamic type when multiple items have different dynamic types? ANSWER: (1) Yes. (2) No, it was not intended for array constructors to be polymorphic. A polymorphic array value, if desired, can be safely constructed by using an allocatable array function. (3) Not applicable. An edit is provided to clarify the situation. EDITS: [67:21] "same type" -> "same declared type" [68:9] "type and" -> "declared type and" [68:14+] Insert new paragraph "The dynamic type of the array constructor is the same as its declared type." SUBMITTED BY: Van Snyder HISTORY: 07-231 m180 F03/0090 submitted (revised by M. Cohen) 07-231 m180 Passed by J3 meeting 07-272 m181 Failed J3 letter ballot #13 07-250r1 09-266 m189 Revised answer. ---------------------------------------------------------------------- Jim Xia's NO vote on F03/0090: Answer (2) of the interp says an array constructor is non-polymorphic with declared type and dynamic type both of T. I see at least four problems with this answer: 1) There is no requirement anywhere in the standard for RHS expression be non-polymorphic in an intrinsic assignment. The array constructor can surely be interpreted as a polymorphic array, and the effect is the same as if a polymorphic pointer/ allocatable array appears as the RHS expression in the assignment. This interpretation will give the same results for the assignment. REPLY: (a) We did not intend to add polymorphic array constructors. (b) Polymorphic array constructors would be more error-prone than constructing values using user-defined functions. (c) Constructing a polymorphic array value requires more effort than a nonpolymorphic value, and it is significantly less obvious (than a user function reference) that that is what is going on. (d) With zero-trip DO loops, array constructors of type CHARACTER have already proven problematic; it would be highly undesirable to reintroduce those problems with dynamic type polymorphism. ASIDE: There is nothing in the interpretation question or answer which is narrowly focussing on the question of intrinsic assignment. 2) There are other potential usage of an array constructor containing polymorphic entities, such as an actual argument to be associated with a polymorphic dummy array, a selector in ASSOCIATE or SELECT TYPE construct, a in an ALLOCATE statement for a polymorphic pointer/allocatable array. It's appropriate to interpret it as a polymorphic array with the same declared type and dynamic type as those appearing in the array constructor, respectively. REPLY: Same as above. 3) This interpretation prohibits use of unlimited polymorphic data in an array constructor because they don't have a declared type. There is no rationale in banning unlimited polymorphic entities in an array constructor. REPLY: Same as (b) above, plus (e) More than one unlimited polymorphic array constructor item is already prohibited because two unlimited polymorphic entities do not have the same declared type (they have no declared type). 4) The same effect of obtaining a non-polymorphic array constructor can already be achieved by using . REPLY: (f) That there is more than one way of performing an operation is not a flaw in the standard. (g) Since is declaratory, and has no place for the CLASS keyword that normally indicates polymorphism, it could be quite confusing for the user to have this behave differently. ---------------------------------------------------------------------- 3. Alternative answer and edits sections ANSWER: (1) Yes. (2) Yes, it was intended for array constructors to be polymorphic. (3) Every item must have the same dynamic type. An edit is provided to clarify the situation. EDITS: [67:21] "same type" -> "same declared type". {We cannot require anything about dynamic type in a constraint.} [68:8] Before "length" insert "dynamic type and". {Require all the expressions to be the same.} [68:14+] Insert new paragraph "If does not appear, the dynamic type of the array constructor is the same as that of the array constructor items. If any is polymorphic and does not appear, no shall appear in an whose iteration count is zero." {The last sentence is an attempt to defuse array constructors with ambiguous types, but is not really satisfactory.} ---------------------------------------------------------------------- ===END===