Alvaro Fernandez wrote:
> I'm sorry, but that's not what I mean... Clearly, you can have two
> functions/routines, put them in an interface block directly or through
> the MODULE PROCEDURE statement, and have the compiler pick among them by
> "disambiguating" based upon the kinds of the arguments being passed in
> and the kinds of the dummy arguments waiting to receive them in the
> procedure. The compiler swaps the generic name sin() for
> sin_single_precision, and away we go - compile-time polymorphism.
>
> But what Van Snyder said was that he had a _single version_ which he
> wrote for all kinds and selected internally. That's at least what I
> understood.
There is a proposal for that (two, so far, although I've not officially
submitted mine yet since it overlaps with several other proposals
and I want to see how they fare). Mine goes something like this:
Function mean(r1,r2)
integer, inferred :: k1, k2
real(^k1)::r1 ! k1 is implicitly set to the value of r1's KIND
real(^k2)::r2 ! k2 in implicitly set to the value of r2's KIND
real(kind(0.0_k1+0.0_k2)) :: mean ! mean's KIND is determined by the
usual rule
mean = (r1+r2)/2
end function mean
This function is now generic with respect to KIND. The definition of
the named constants in that form is called "inference".
--
J. Giles
|