I have a PhD in computational fluid dynamics (CFD), and have written several CFD codes in Fortran, C, Matlab and Python. I'm also a programming language geek, and have been interested in functional programming languages for quite some time. When I see something like this, however, I loose some of my faith. It just seems like too much effort to get decent speed, and even when not considering speed it doesn't seem to give much benefit. For instance, this is how the diffusion function would look in Fortran (skipping some details):<p><pre><code> pure function diffusion(x0) result(x)
real, intent(in), dimension(:,:) :: x0
real, intent(out),dimension(:,:) :: x
x = x0(2:n+1,1:n ) &
+ x0(0:n-1,1:n ) &
+ x0(1:n ,2:n+1) &
+ x0(1:n ,0:n-1) &
-a*x0(1:n ,1:n )
end function
</code></pre>
Some things to note:<p>- The "pure" keyword guarantees that this function has no side effects.<p>- No do loops are needed! Fortran array slicing is very handy.<p>- The compiler will convert this to use SIMD instructions<p>- Adding some OpenMP hints to make it run on all cores is also very easy.<p>So this type of code in Fortran is short, very easy to understand and you are guaranteed extreme performance. Maybe functional programming has some benefits when you're dealing with more complex datastructures (for instance I'm working on a code right now which uses parallel octrees, kind off a pain in Fortran), but for simple things like this, I fail to see the point.<p>I want to believe, so perhaps someone here can enlighten me?