[J3] [EXTERNAL] Elemental type-bound functions not useful

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Mon Mar 29 12:51:20 UTC 2021


From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Sunday, March 28, 2021 at 7:13 PM
To: j3 <j3 at j3-fortran.org>
Cc: Van Snyder <van.snyder at sbcglobal.net>
Subject: [EXTERNAL] [J3] Elemental type-bound functions not useful

The passed-object dummy argument of a type-bound function has to be polymorphic. The result of an elemental function cannot be polymorphic, because it cannot be allocatable or a pointer. This makes elemental type-bound functions not really useful because in a type extension, the result of the type-bound function is still of the declared type.

Did I miss something that makes them useful?

Yes – all the cases where the type-bound function does not return a polymorphic result.    Indeed, this has little to do with type-bound functions.

Is there something that can be done to make them useful?

When OO was being developed, there were proposals for CLASSOF and TYPEOF declarations, to specify that some entity had the same class or type as another. Those proposals failed. Could something like that make type-bound elemental functions useful?

The proposals did not fail.

Is it absolutely necessary for a passed-object dummy argument to be polymorphic? An alternative is to require that one that does not have a polymorphic passed-object dummy argument is overridden in extensions.

This would not help you.  If your return type is polymorphic, then it still cannot be elemental.   And if the goal is to have a result that is a  concrete type that varies with each subclass, then just add a specific such method to each subclass.      You just cannot overload the interfaces because that leads to ambiguity.

Cheers,


  *   Tom


An onerous alternative is to require that type-bound elemental functions that have the same result type as the declared type are overridden in every extension. Ugh. Users should do this, but what a burden!

Another onerous alternative is for users to provide a non-elemental function for every rank. It was precisely to avoid this that elemental functions were invented.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210329/8d5a4b3c/attachment-0003.htm>


More information about the J3 mailing list