On 2015-04-15 6:23 PM, Stefano Zaghi wrote:
> Do you like the idea of FortranFan et al.?
I have been away for a few days, and else-thread the discussion has
progressed, but I think Wolfgang has already expressed most of the
conceptual capabilities that I would like to see in a generic
programming enhancement to Fortran, particularly around the need to be
able to describe in-source the requirements that my generic code might
have on the client types and procedures that it might work on, such that
when I, as a client programmer, fail to meet those requirements, the
processor can effectively help me fix my mistake.
One point that might not have been raised though - I'm not so sure that
the best approach to parameterisation is at the type level - i.e as we
have now with kind and length parameters. With the language as it is,
it may be more effective if parameterisation was done at the module and
submodule level. Coming at it from the perspective of a library author
writing generic code - you typically want to provide a *package* of
types (plural), procedures and perhaps variables to the clients of your
library, that all have a common compile time parameterisation. The
current means of packaging code in Fortran is a module.
This is in the context of the current design of the language compared
with other languages - particularly that procedures are not members of a
type.
This is motivated in part by my experience with kind type parameters in
F2003, compared with length type parameters. I find kind type
parameters of marginal use in their current form in the current language
- you pretty much have to know at the time that you write the type and
its accompanying procedures the singular "value" of the kind parameter
(which might be specified by a named constant) that you will support.
You can easily parameterise the type, but not the procedures that use
the type - all the kind parameterisation is offering you is some
namespace nicety. On the other hand, with length parameters, you can
provide in a package both a type and procedures that will support
multiple values of the length parameter with the one chunk of code.
I'd also like to see the ability to parameterise modules for aspects
other than type - integer parameterisation for example.
As a parallel feature, you may also want to have type based
parameterisation of types and type and integer parameterisation of
procedures. Integer parameterisation of procedures would go a long way
towards resolving the current issues with kind type parameters.
For parameterised procedures, I think I favour explicit instantiation
(this identifier is this parameterised procedure instantiated with these
parameters), rather than the implicit instantiation (look at the
arguments, try and work out what parameter values result in a valid call).
Other aspects to consider include whether parameter that is a type is
just a type, a type spec (i.e. with type parameters), or a declaration
type spec (CLASS/TYPE); for procedures whether you can parameterise out
attributes such as argument INTENT (c.f. const versus non-const
parameterisation in C++); if a module is parameterised under what
conditions are module variables considered unique instances; can you
parameterise out rank; should there be the capability for specialisation
and incomplete specialisation, etc, etc, etc, etc...
I've played with some options for implementation of some of these
features, but haven't got very far.