toDigits :: Integer -> [Integer] toDigits x | x <= 0 = [] | divBy10 < 10 = [divBy10, remainder] | otherwise = toDigits divBy10 ++ [remainder] where remainder = x `mod` 10 divBy10 = x `div` 10