<div dir="ltr"><div>The error lies here:</div><div><br></div><div><font face="monospace, monospace">toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` 10))</font><br></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">It should instead be</font></div><div><br></div><div><span style="font-family:monospace,monospace">toDigits' acc number = (number `mod` 10) : (toDigits' acc (number `mod` 10))</span><br></div><div><br></div><div>My suggestion would be to look at it like a fold.<br></div><div><br></div><font face="monospace, monospace">toDigits' :: Integral a => a -> a -> [a]</font><div><font face="monospace, monospace">toDigits' acc 0 = [acc]</font></div><div><font face="monospace, monospace">toDigits' acc n = n `mod` 10 : toDigits' acc (n `div` 10)</font></div><div><br class="">Now this gives the digits in the reverse order, so in toDigits, you can reverse it.<font face="monospace, monospace"><br></font></div><div><br></div>A good exercise would now be to re-write this as a fold. Graham Hutton has a good paper about it. [1]<div><br></div><div>The best way would be to directly convert the number to a string using show, but that's not the point of the exercise.<br><div><br></div><div>[1]: <a href="https://www.cs.nott.ac.uk/~gmh/fold.pdf">https://www.cs.nott.ac.uk/~gmh/fold.pdf</a></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 May 2015 at 12:28, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
For some reasons my file's are corrupted.<br>
I had repair them with success except this one.<br>
<br>
Here is the code :<br>
<br>
toDigits number<br>
| number <= 0 = []<br>
| otherwise = toDigits' [] number<br>
where<br>
toDigits' acc 0 = acc<br>
toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` 10))<br>
<br>
main = print $ toDigits 123<br>
<br>
<br>
and here is the error:<br>
<br>
Couldn't match expected type `(a0 -> [a0]) -> [a0]'<br>
with actual type `[a0]'<br>
The function `(number `mod` 10) : acc' is applied to one argument,<br>
but its type `[a0]' has none<br>
In the expression:<br>
((number `mod` 10) : acc) (toDigits' (number `mod` 10))<br>
In an equation for toDigits':<br>
toDigits' acc number<br>
= ((number `mod` 10) : acc) (toDigits' (number `mod` 10))<br>
<br>
<br>
Roelof<br>
<br>
<br>
---<br>
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.<br>
<a href="http://www.avast.com" target="_blank">http://www.avast.com</a><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>