When using channels as function parameters in Co-array Fortran, we can specify if a channel is meant to only send or receive values. This specificity increases the type-safety of the program.
In this example, we’ve simulated channels using a custom type string_channel. The ping subroutine is designed to only send values, while the pong subroutine both receives and sends.
To run the program:
Note that Co-array Fortran doesn’t have built-in channel semantics like Go. Instead, we’ve used a simple struct-like type to simulate channel behavior. The intent attributes in Fortran help enforce the directionality of our simulated channels.
In a real Co-array Fortran program, you might use co-arrays for inter-image communication, which would be more idiomatic for the language. However, this example focuses on simulating Go’s channel directions concept.