[J3] [EXTERNAL] Elemental type-bound functions not useful
Damian Rouson
damian at sourceryinstitute.org
Tue Mar 30 01:32:50 UTC 2021
On Mon, Mar 29, 2021 at 6:11 PM Van Snyder via J3 <j3 at mailman.j3-fortran.org>
wrote:
>
> Fortran doesn't yet have "sealed" or "inextensible" types (unless I missed
> something that prevents creating an extension type).
>
One can prevent type extension by declaring a type-bound generic procedure
with the same name as the name of the type as one might do to
effectively write a type-bound, user-defined structure constructor:
type foo
contains
procedure :: foo_constructor
generic :: foo => foo_constructor
end type
My thoughts are aligned with those of Tom and Vipul. Once Fortran
supports generic programming, I suspect it will displace type extension for
most of my purposes. For now, I strive to limit type extension to extending
abstract types. We sometimes have a non-abstract type extending an abstract
type that extends another abstract type, but that's as deep as
our hierarchies go in practice. We frequently combine type extension with
type-bound operators, but I'm not crazy about the type-guarding that this
approach requires. It feels like the developer is being burdened with
ensuring runtime type safety as a stand-in for compile-time type safety,
which is why I suspect I'll replace type extension with generic
programming.
Damian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210329/2adffd7e/attachment-0003.htm>
More information about the J3
mailing list