I'm relatively new to Haskell and rather inexperienced with programming in general. A function is causing a stack overflow on certain inputs and I'm not sure why.
Function in question:
digitSum :: Integer -> Integer -> Integer
digitSum _ 1 = 1
digitSum base x = (x `mod` base) + digitSum base (x `div`base)
On some inputs (e.g. 10 15, 11 121, 16 19, 3 1234) it works while on others (10 456 for example) it breaks Could someone explain this to me, so that I can avoid it in the future?