[Haskell-beginners] Problem with an if statement

Karol Samborski edv.karol at gmail.com
Wed Nov 9 10:17:46 CET 2011


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 <edv.karol at gmail.com>:
> 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
>



More information about the Beginners mailing list