[Haskell-beginners] recursion problem.

Marcin Mrotek marcin.jan.mrotek at gmail.com
Fri Feb 6 10:27:56 UTC 2015


Ah, sorry, I didn't think of that when I responded to your other
thread. You can always insert a check before recursion:

toDigits :: Integer -> [Integer]
toDigits n
 | n < 0 = []
 | otherwise =  (if n' > 0 then toDigits n' else []) ++ [n `mod` 10]
     where n' = n `div` 10

Regards,
Marcin Mrotek


More information about the Beginners mailing list