[Haskell-beginners] sum problem

yi lu zhiwudazhanjiangshi at gmail.com
Sat Feb 7 09:01:48 UTC 2015


Do not try to `sum` all at first. See how you can deal with one integer.

On Sat, Feb 7, 2015 at 4:53 PM, Roelof Wobben <r.wobben at home.nl> wrote:

> Hello,
>
> The exercises of CIS 194 are really hard.
>
> Now I have to sum all the numbers in a array with a catch
> If a number is greater then 10 it has to be dived in single numbers.
>
> so [ 1 , 12, 3] will be [ 1, 1,2,3] and then sum up.
>
> So far I have this :
>
> -- | sum all the digits of a array
> sumDigits :: [Integer] -> Integer
> sumDigits n
>    | n == 0 = acc
>    | n < 10 = acc + n
>    | otherwise = sumDigits acc + n `mod` 10 + n `rem` 10
>
>
> But now I see a message that acc is not known which is not wierd.
>
> But when I do sumDigits n acc I see a message that sumDigits has only 1
> parameter where I give it to,
>
> When I only had to sum up i is easy , I could use map [+] xs
>
> Anyone  who can give a me tip without giving the answer otherwise I do not
> learn anything.
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150207/003d8fe5/attachment.html>


More information about the Beginners mailing list