Last active
June 1, 2023 18:06
-
-
Save dorchard/3cc13fe75d6d109cb75ec11d41ddc104 to your computer and use it in GitHub Desktop.
Fortran, function overloading on arity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program example | |
use naryfunc | |
implicit none | |
! Outputs 2 6 24 | |
write(*,*) mult(2), mult(2, 3), mult(2, 3, 4) | |
end program example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module naryfunc | |
implicit none | |
private | |
public mult | |
interface mult | |
module procedure mult1, mult2, mult3 | |
end interface | |
contains | |
pure function mult1(x) | |
integer, intent(in) :: x | |
integer :: mult1 | |
mult1 = x | |
end function mult1 | |
pure function mult2(x, y) | |
integer, intent(in) :: x, y | |
integer :: mult2 | |
mult2 = x * y | |
end function mult2 | |
pure function mult3(x, y, z) | |
integer, intent(in) :: x, y, z | |
integer :: mult3 | |
mult3 = x * y * z | |
end function mult3 | |
end module naryfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment