Introduction
- Enhanced facility toward Generics in Fortran is a major focus of Fortran 202Y standard revision with several items on the worklist,
- In response to Community feedback and also push from another national body, WG5 has also decided to, “Investigate other mechanisms for simplifying the use of templates.”
- Among the most frequently expressed needs toward Generics by the user Community include
a. Generic subprograms e.g., add ability to author a procedure such as FINDLOC in Fortran that works on any supported type of the language
b. Generic containers e.g., add ability to parameterize a derived type in Fortran with any supported type such as a list type (linked list, trees, etc.) or stack, etc. - TKR semantics around Type (T), Kind (K), and Rank (K) is a fundamental aspect of generic resolution in Fortran,
- Increasingly Attribute (A) is proving extremely important; Fortran 2008 recognized this and allowed ALLOCATABLE and POINTER attributes in generic resolution.
Proposal:
KART aspect around Kind (K), Attribute (A), Rank (R), and Type (T) is recommended as an integral element of the design toward enhanced Generics in Fortran starting with Fortran 202Y.
Premise:
- Fortran language introduces an entity block similar to interface block in current language standard (c.f. 3.87 interface block, Terms and Definitions, Fortran 2023),
- A generic entity block and a specific entity block are part of this introduction
- KART is a basic builiding element of the entity block
- The entity block
- provides a structured manner of collections of KIND, ATTRIBUTE, RANK, and TYPE of the entity, similar to an
INTERFACE
block - serves toward the generic resolution,
- follows the generics-by-substitution design philosophy,
- builds on existing facilities in the language toward generics
- provides a structured manner of collections of KIND, ATTRIBUTE, RANK, and TYPE of the entity, similar to an
Examples:
NOTE: syntax employed in the examples is notional only, especially the use of carats (<..>
). The Community feedback shall permit better syntax development.
- Generic “accumulator” method toward intrinsic numeric types with all their supported kinds
module m
generic, entity :: T
type => intrinsic_numeric
end generic
contains
subroutine accumulate<T>( x, a )
<T>, intent(inout) :: x
<T>, intent(in) :: a
x = x + a
end subroutine
end module
- Usage
..
use m
..
real :: r
..
call accumulate<real>( r, 1.0 )
- Generic Container for a stack of any type but with the
ALLOCATABLE
attribute
module stack_m
generic, entity :: T
type => *
attribute => allocatable
end generic
type :: stack_t<T>
<T> :: node
type(stack_t), allocatable :: next
end type
contains
..
end module
Next steps: a lot needs to be developed with great effort, but hopefully this initial post can lead toward influencing the language development with support of KART semantics as an integral element of the design of Generics in Fortran.