Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Haskell from C: Where are the for Loops? (fpcomplete.com)
4 points by behnamoh on Dec 1, 2021 | hide | past | favorite | 2 comments


In modern Fortran you don't need a loop either. The code to compute the norm of a vector of a billion integers starting with zero is

   program main
   implicit none
   integer         , parameter   :: n = 10**9
   double precision, allocatable :: x(:)
   integer                       :: i
   allocate (x(n))
   forall (i=1:n) x(i) = dble(i-1)
   print*,sqrt(sum(x**2))
   end program main


print *, norm2(x)

"The result of NORM2 (X) has a value equal to a processor-dependent approximation to the generalized L2 norm of X, which is the square root of the sum of the squares of the elements of X. If X has size zero, the result has the value zero."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: