[J3] Type-bound procedures required to be module procedures
Van Snyder
van.snyder at sbcglobal.net
Tue Dec 28 22:16:40 UTC 2021
I started out on a small program that needed two related types -- one
had the same components as the other, and a few ore. The program is
sufficiently small that it doesn't need to have modules. Everything
would comfortably fit in the main program.
The obvious thing to use was an extension type.
I needed to be able to sort objects of those types.
I added a type-bound Sort procedure as an internal procedure of the
main program. Then the compiler reminded me that type-bound procedures
are required to be module procedures.
Is there a technical reason for this requirement? It prevents having a
type and its type-bound procedures defined in the same scoping unit
unless that scoping unit is a module.
The sort routine itself is difficult because one cannot assign a value
to an element of a polymorphic array -- because the element is
polymorphic but not allocatable. But that's already been the topic of
another discussion. Instead of sorting in place, one must produce a
permutation vector.
Two useful extensions in the next revision would be
1. Allow any procedure that is accessible at the point of definition
of a type to be a type-bound procedure.
2. Allow assignment to non-allocatable polymorphic variables. If the
dynamic types of the expression and variable are different, an
error condition exists. As with, for example, an error in an
intrinsic function such as sqrt(-1.0), the program cannot detect
the error. When block-structured exception handling is added, a
program can detect the error. A pre-exception-handler alternative
is a statement that encloses an assignment statement and includes
STAT= and ERMSG= specifiers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20211228/fcd748f5/attachment.htm>
More information about the J3
mailing list