DTIO, DTP, and Submodules

Holcomb, Katherine A. (kah3f) kah3f@eservices.virginia.edu
Mon Oct 6 22:54:00 GMT 2014


I¹ve been mulling over this thread for a while and don¹t want to start a
flamewar, but I have some opinions on generics.


>
>
>Nevertheless, if the Trilinos people have a useful proposal to the
>Fortran committee (http://j3-fortran.org), I am surely willing to work
>to beat it into something that can produce meaningful discussions in the
>committee.


I would *really* like to have some ability at minimum to state that a
function/subroutine is valid for both single and double.  I have a number
of little modules I¹ve written for my own needs (sorters, some math
functions, etc.) and it is a major pain in the ### to have to write two
versions for each and every such routine when it is very rare to need
different code for the two types.  As far as I can tell, the best one can
do is declare variables with a kind variable, then drag around a separate
module that declares the kind parameter.  (So I suppose kinds are sort of
but not quite generics.)  I sometimes give my modules to students and
others so I would rather not assume a kind parameter name.

Adding integer could be problematic since it is a never-ending source of
surprise to most inexperienced programmers that a*b/c gives different
results for 
a=3.; b=4.; c=21. than for
a=3, b=4, c=21
And of course complex is something else entirely (yet for a given function
it might work).

I¹ve been looking at Swift and it allows "type constraints" in generics.
One defines a ³protocol" and then can declare that a template is valid
only for things that support the protocol.  That way you cannot, for
instance, pass a type that doesn¹t have = defined to a procedure that
requires it. Swift seems to be like Python in that everything, including
what seem to be primitive types, is an object.  It¹s also typed by
inference though one can override that with a declaration.  Those features
presumably simplify this, but it seems like a good idea.  E.g. to solve my
problem above, one might be allowed to (or the language might include) a
³protocol" Float or some such.




>
>-- 
>Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290



More information about the Fortran mailing list