The following code gives me a stack overflow error in some cases (ex hosum (\x->x `mod` 3) 1000 ) and I don't understand why. Could anyone explain this to me? (I am new to Haskell and I'd appreciate any help :) )
hosum :: (Int -> Int) -> (Int -> Int)
hosum f = (\x -> hs f x (- x))
where hs :: (Int -> Int) -> Int -> Int -> Int
hs f 0 0 = f 0
hs f n m
| m <= n
= f m + hs f n (m+1)
| n <= m
= f n + hs f (n+1) m
| otherwise
= 0