The error lies here:
toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` 10))
It should instead be
toDigits' acc number = (number `mod` 10) : (toDigits' acc (number `mod` 10))
My suggestion would be to look at it like a fold.
toDigits' :: Integral a => a -> a -> [a]toDigits' acc 0 = [acc]
toDigits' acc n = n `mod` 10 : toDigits' acc (n `div` 10)
Now this gives the digits in the reverse order, so in toDigits, you can reverse it.
A good exercise would now be to re-write this as a fold. Graham Hutton has a good paper about it. [1]
The best way would be to directly convert the number to a string using show, but that's not the point of the exercise.