j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Packaging without polymorphism #281

Open rouson opened 2 years ago

rouson commented 2 years ago

Using a derived type foo_t in a module foo_m automatically gives access to all of the type's public type-bound procedures:

use foo_m, only : foo_t
type(foo_t) foo
call foo%bar

without the need to explicitly name the public type-bound procedures (e.g., bar) in the use statement's only clause. This can be very convenient in that it obviates the need to provide a potentially long list of procedures in the only clause. However, this capability is inextricably linked to polymorphism by the requirement that the passed-object dummy argument must be declared with the keyword class. It would be nice to have some sort of packaging mechanism that makes a collection of procedures accessible wherever a related type is accessible without also inherently enabling polymorphism, which obligates the programmer to perform runtime checks of the passed-object dummy argument's dynamic type in some situations in order to ensure type safety.

rouson commented 2 years ago

I'm unclear on to what extent this request overlaps with #87.

FortranFan commented 2 years ago

@rouson , can you please take another look at #37 that proposes an "option to derive an inextensible type" in Fortran?

You will notice one of the benefits of that proposal will be to make it easier to "package" related methods (and data) into public "class" i.e., a derived type without having to deal with polymorphism.

37 may not cover everything you have in mind and I believe #37 will be valuable on its own, but if you can give #37 a thought and share your feedback on it, it will be useful.

rouson commented 2 years ago

@FortranFan thanks for pointing me to #37. I had not noticed it before and will read it shortly.

rouson commented 2 years ago

@FortranFan I just clicked thumbs-up on #37. I agree that it would be one way to achieve the same ends as my proposal.