[J3] [EXTERNAL] Elemental type-bound functions not useful
Van Snyder
van.snyder at sbcglobal.net
Mon Mar 29 21:03:04 UTC 2021
On Mon, 2021-03-29 at 20:07 +0000, Clune, Thomas L. (GSFC-6101) wrote:
> OK – I have a bit more time now. Slowing down ….
>
>
>
> So, you have a type and want an elemental procedure that acts on that
> type and returns something of the same type. And you don’t want to
> allow that procedure to work on type extensions. You therefore do
> _not_ want a type-bound
> procedure, as that is contrary to the intent of such constructs.
> Rather, you just want plain old F90 elemental function. It will
> pollute name space a bit more since it will need to be made public,
> but it otherwise seems to meet your requirements. You
> can even overload it with similar functions for type extension now,
> since the equivalent of the passed-object dummy can now be declared
> with TYPE instead of CLASS.
Without a type-bound procedure, you can't have a generic binding. So
instead of
use MyModule, only: MyType
you need
use MyModule, only: MyType, operator(+), operator(-), operator(*),
operator(/), operator(**), operator(==), & operator(/=), operator(>),
operator(<), operator(>=), operator(<=), cos, sin, exp, log, abs,
dot_product, matmul, ....
or just
use MyModule
The advantage of the former, which many organizations' style guides
require, is that by looking only at the module where it's used, you can
see where everything comes from, rather than using "grep" to find it.
>
>
> From:
> "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
>
> Date: Monday, March 29, 2021 at 3:12 PM
>
> To: j3 <j3 at mailman.j3-fortran.org>, j3 <j3 at j3-fortran.org>
>
> Cc: Van Snyder <van.snyder at sbcglobal.net>
>
> Subject: Re: [J3] [EXTERNAL] Elemental type-bound functions not
> useful
>
>
>
>
> Sorry was typing faster than thinking. NON_OVERRIDABLE is not quite
> what you want.
>
>
>
> From:
> "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
>
> Date: Monday, March 29, 2021 at 3:07 PM
>
> To: j3 <j3 at mailman.j3-fortran.org>, j3 <j3 at j3-fortran.org>
>
> Cc: Van Snyder <van.snyder at sbcglobal.net>
>
> Subject: Re: [J3] [EXTERNAL] Elemental type-bound functions not
> useful
>
>
>
>
> If you don’t want that (and I think there are times when you would),
> that is precisely what the NON_OVERRIDABLE attribute is for. As I
> said before, you can’t overload the same name for these types of
> type-bound
> procedures anyway (because they are only distinguished by the return
> type), so just invent a unique name for each subclass that needs this
> elemental method and make each one NON_OVERRIDABLE.
>
>
>
> 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: Monday, March 29, 2021 at 2:48 PM
>
> To: j3 <j3 at j3-fortran.org>
>
> Cc: Van Snyder <van.snyder at sbcglobal.net>
>
> Subject: Re: [J3] [EXTERNAL] Elemental type-bound functions not
> useful
>
>
>
>
>
> On Mon, 2021-03-29 at 18:25 +0000, Clune, Thomas L. (GSFC-6101)
> wrote:
>
> > Why? The restriction on elemental is that the return type not be
> > polymorphic. There is no restriction that the passed-object dummy
> > be non-polymorphic.
>
>
>
>
> If the dummy argument is polymorphic, the function can be invoked
> using an actual argument for which the type is an extension of the
> result type.
>
>
>
>
> >
> >
> >
> > 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: Monday, March 29, 2021 at 2:18 PM
> >
> > To: j3 <j3 at mailman.j3-fortran.org>
> >
> > Cc: Van Snyder <van.snyder at sbcglobal.net>
> >
> > Subject: Re: [J3] [EXTERNAL] Elemental type-bound functions not
> > useful
> >
> >
> >
> >
> >
> > On Mon, 2021-03-29 at 12:59 +0000, Clune, Thomas L. (GSFC-6101) via
> > J3 wrote:
> >
> > > I meant to add that the use case you are describing is
> > > essentially the poster child for templates vs OO. When the
> > > return type varies with the input type, templates are a very
> > > natural fit, and trying to force OO is tricky at best.
> >
> >
> >
> >
> > This doesn't solve the problem unless type-bound functions are
> > allowed not to have polymorphic passed-object dummy arguments.
> >
> >
> >
> >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210329/543c670d/attachment.htm>
More information about the J3
mailing list