[J3] Same specific procedure for multiple type-bound procedures?
Malcolm Cohen
malcolm at nag-j.co.jp
Tue Jan 28 23:27:21 UTC 2025
Hi Daniel,
Without looking at the code, of course the same *actual* procedure could be
used to implement more than one type-bound procedure.
Do not use the word specific here: specific has a technical meaning, and you
will just confuse yourself. Asking whether the same *specific* procedure can
be used for more than one type-bound procedure is *meaningless*. Type-bound
procedures are themselves *specific* (unless they are generic, of course,
just like procedure names are specific unless they are generic).
One binds an *actual* (or "ordinary" if you prefer) procedure to be the
implementation of a *specific* type-bound procedure. The type-bound
procedure is not the actual procedure, the actual procedure is merely the
implementation *in that type*.
A generic named procedure is a set of *specific* ordinary procedures that
satisfy the ambiguity rules.
A generic type-bound procedure is a set of *specific* type-bound procedures
that satisfy the ambiguity rules.
It is all very simple and consistent: "named generic: set of named
procedures" and "type-bound generic: set of type-bound procedures". In the
type-bound procedure case, it does not matter what the implementing
procedures are, it is the type-bound procedures that must satisfy the
generic rules. That is because the type-bound procedures can be overridden
individually, so generic resolution absolutely needs non-ambiguous
resolution: whether one of the types uses the same actual procedure to
implement two type-bound procedures is simply irrelevant and unhelpful to
consider.
When the generic type-bound procedure is an operator, the resulting generic
set will consist of all procedures, type-bound or otherwise, with that
operator symbol in a scope. The ambiguity rules in 15.4.3.4.5 work equally
on pairs of named procedures, pairs of type-bound procedures, and pairs
consisting of one named procedure and one type-bound procedure.
BOTH of your examples are invalid because the specific type-bound procedures
do NOT satisfy the ambiguity rules:
Error: chen1.f90, line 24: Ambiguous specific type-bound procedures G and F
for type-bound generic OPERATOR(+) in type BASE1
Error: chen2.f90, line 18: Ambiguous specific type-bound procedures BASE2
and BASE1 for type-bound generic OPERATOR(+) in type BASE
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Daniel Chen via J3
Sent: Wednesday, January 29, 2025 6:04 AM
To: Van Snyder via J3 <j3 at mailman.j3-fortran.org>
Cc: Daniel Chen <cdchen at ca.ibm.com>
Subject: [J3] Same specific procedure for multiple type-bound procedures?
Hello,
As in the following code,
Case 1:
```
module m
type base
integer :: i = -999
contains
procedure, pass(b) :: g => int_base1_base !! Same specific
generic :: operator(+) => g
end type
type base1
integer :: j = -999
contains
procedure, pass :: f => int_base1_base !! Same specific
generic :: operator(+) => f
end type
contains
integer function int_base1_base ( a, b )
class(base1), intent(in) :: a
class(base), intent(in) :: b
end function
end module
```
Case 2:
```
module m
type base
integer :: i = -999
contains
procedure, pass(b) :: base1 => base_base_base !! Same specific
procedure, pass(b) :: base2 => base_base_base !! Same specific
generic :: operator(+) => base1, base2
end type
contains
type(base) function base_base_base ( a, b )
class(base), intent(in) :: a
class(base), intent(in) :: b
end function
end module
```
Are these 2 cases legal? Can multiple binding-name from either different
types or the same type point to the same specific procedure?
I didn't find any wording in the standard that disallows it.
Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250129/a9e46229/attachment.htm>
More information about the J3
mailing list