How to code the following pseudo-code in Haskell?
x=0
for (i from 0 to 100):
j=0
while ( f(i,j) >0 ):
x+= f(i,j)
j+=1
(f some unimportant function.)
I came up with something like this:
a= [x| i<-[0..100], let s = takeWhile (\k-> (f i k > 0)) [0..],
j<- s, let x = f i j ]
Then Sum a does the work, but I need to compute f i j two times which is a little bit redundant.
Can this be done with f computed only once or some better codes that run faster?