
Hi, With a function defined like this (colors is type of Array Int [Int] and edges is [Int]): saturation (_,edges,_) = foldr (\ed ac ->if null (colors!ed) then ac else ac+1) 0 edges I'm getting an infinite loop. But when I remove the if statement like this: saturation (_,edges,_) = foldr (\ed ac -> ac+1) 0 edges everything's working. How should I define my function with the if statement to not getting an infinite loop? Best Regards, Karol Samborski

I forgot to mention that this definition:
saturation (_,edges,_) = length $ foldr (\ed ac -> colors!ed : ac) [] edges
is working too.
I don't understand why the version with an 'if' is not working.
Best Regards,
Karol Samborski
2011/11/9 Karol Samborski
Hi,
With a function defined like this (colors is type of Array Int [Int] and edges is [Int]): saturation (_,edges,_) = foldr (\ed ac ->if null (colors!ed) then ac else ac+1) 0 edges I'm getting an infinite loop.
But when I remove the if statement like this: saturation (_,edges,_) = foldr (\ed ac -> ac+1) 0 edges everything's working.
How should I define my function with the if statement to not getting an infinite loop?
Best Regards, Karol Samborski

Oh, nevermind. The problem was in other place not in that function.
I'm sorry for this...
Best Regards,
Karol Samborski
2011/11/9 Karol Samborski
I forgot to mention that this definition: saturation (_,edges,_) = length $ foldr (\ed ac -> colors!ed : ac) [] edges is working too.
I don't understand why the version with an 'if' is not working.
Best Regards, Karol Samborski
2011/11/9 Karol Samborski
: Hi,
With a function defined like this (colors is type of Array Int [Int] and edges is [Int]): saturation (_,edges,_) = foldr (\ed ac ->if null (colors!ed) then ac else ac+1) 0 edges I'm getting an infinite loop.
But when I remove the if statement like this: saturation (_,edges,_) = foldr (\ed ac -> ac+1) 0 edges everything's working.
How should I define my function with the if statement to not getting an infinite loop?
Best Regards, Karol Samborski
participants (1)
-
Karol Samborski