<p dir="ltr"><br>
Am 05.02.2015 17:29 schrieb "Marcin Mrotek" <<a href="mailto:marcin.jan.mrotek@gmail.com">marcin.jan.mrotek@gmail.com</a>>:<br>
><br>
> Well, toDigits is always finishing its work after dividing the input number once, and always returns lists of at most one element. You need it to call itself recursively until it's done, and append the calculated digit to the result:<br>
><br>
> toDigits :: Integer -> [Integer]<br>
> toDigits n<br>
>   | n <= 0 = []<br>
>   | otherwise = n `mod` 10 : toDigits (n `div` 10)</p>
<p dir="ltr">This doesn't feel right:</p>
<p dir="ltr">toDigits 10 = 0 : toDigits 1 = 0 : 1 : toDigits 0 = 0 : 1 : [] = [0,1]</p>
<p dir="ltr">I'd expect the result to be [1,0]...</p>
<p dir="ltr">><br>
> The <= is necessary, otherwise the function would loop infinitely on 0. This version will print the digits in reverse, so you might move the code to a local function in toDigits, and make toDigit call it and then reverse the result.<br>
><br>
> I'd strongly recommend reading a Haskell tutorial (for example <a href="http://learnyouahaskell.com">http://learnyouahaskell.com</a> ) to learn the basics.<br>
><br>
> Kind regards,<br>
> Marcin Mrotek<br>
><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>
</p>