Interfaces in Co-array Fortran are not a native language feature. However, we can simulate similar behavior using abstract types and type-bound procedures. Here’s an equivalent implementation:
In this Co-array Fortran implementation:
We define an abstract type geometry with deferred procedures area and perim. This acts similarly to an interface in other languages.
We create concrete types rect and circle that extend geometry and implement the required procedures.
The measure subroutine takes a geometry object and calls its area and perim methods, demonstrating polymorphism.
In the main program, we create instances of rect and circle, then pass them to the measure subroutine.
To compile and run this program:
This will output the area and perimeter for both the rectangle and circle objects.
Note that Co-array Fortran doesn’t have a direct equivalent to Go’s interfaces, but this approach using abstract types and type-bound procedures provides similar functionality in terms of polymorphism and code reuse.