Reputation: 11
where do i have an endless loop?
f2 :: Int->Int->Int
f2 n d
| d==2
= 0
| n `mod` d ==0 && n`mod` d^3==0
= 1 + (f2 n d-1)
| otherwise
= 0 + (f2 n d-1)
Upvotes: 1
Views: 82
Reputation: 370162
This is a precedence issue. (f2 n d-1)
is parsed as (f2 n d) - 1
, which leads to infinite recursion because f2
is calling itself with the same arguments. You want f2 n (d - 1)
instead.
Upvotes: 9