
6 Feb
2015
6 Feb
'15
8:44 a.m.
Marcin Mrotek schreef op 6-2-2015 om 11:27:
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 _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Hello, Can you explain to me why we need a n' and a where here. I tried the same solution here : toDigitsRev :: Integer -> [Integer] toDigitsRev n | n <= 0 = [] | otherwise = n `mod` 10 : toDigitsRev (n `div` 10) but I could not make it work. Roelof