(j3.2006) Is 7.2.1.2p1(1) necessary?
Malcolm Cohen
malcolm
Thu Mar 12 23:01:46 EDT 2015
I wrote:
> SELECT TYPE is not an assignment, it's type selection.
Van replied:
>Right, but once you reach the block in a TYPE IS, and do an assignment,
>the assignment is type safe.
Absolutely right.
But that requires you to know the universe of possible types so that you can do
the selection. Now, that is reasonable for some (probably most) cases, but I
think not for all.
With a type-bound procedure one can short-cut this to some extent (though at
least sometimes one might still have to do a SELECT TYPE to confirm the dynamic
type of the rhs).
Alternative means of doing "safe polymorphic assignment" could exist if we
wanted them to, e.g.
WHEN SAME TYPE ASSIGN(x = y)
OTHERWISE ERROR STOP
or even
WHEN SAME OR EXTENDED TYPE ASSIGN (x = SAME TYPE PART OF y)
OTHERWISE CONTINUE
(Syntax intended to convey the meaning via email, not remotely intended to be
anything like an actual suggestion!)
This kind of construction would provide type-safe polymorphic assignment without
needing any nested SELECTTYPE or for that matter actually knowing what the
dynamic types specifically are - it only does the assignment when they are the
same, or maybe an extension, whilst avoiding a type error when they are not -
and the user gets to say whether this is a mistake and please abort the mission,
or whether it is benign and not a problem, or whether to take some other action.
We did not add this kind of thing before because
(a) well-founded concern about the overall size of the language;
(b) it's often doable simply with SELECT TYPE and/or type-bound procedures;
(c) it's a minority of cases.
At some time in the future we can certainly revisit this, and many other
decisions, to see if there is some improvement to be made.
Cheers,
--
................................Malcolm Cohen, Nihon NAG, Tokyo.
More information about the J3
mailing list