[Haskell-cafe] recursion problem part 2
Roelof Wobben
r.wobben at home.nl
Fri Feb 6 15:40:01 UTC 2015
Dmitry Olshansky schreef op 6-2-2015 om 16:25:
> toDigits :: Integer -> [Integer]
> toDigits n
> | n < 0 = []
> | n < 10 = [n]
> | otherwise = toDigits (n `div` 10) ++ [n `mod` 10]
>
Thanks that worked,
I have now to figure out why I see [0] on 0 and no zero when it reaches
it end-point.
isDigits 0
n< 10 so [0]
IsDigits 1
n < 0 not true
n < 10 not true.
toDigits 1 ++ [0]
toDigits 1 + [0]
n< 0 not true
n < 10 true so [1] ++ [0]
[1] ++ [0] is [1.0] where the output is [1]
So somehow I do not understand fully how this works .
Roelof
More information about the Haskell-Cafe
mailing list