[Haskell-beginners] sum problem

Joel Neely joel.neely at gmail.com
Sat Feb 7 13:42:21 UTC 2015


Question/hint:  You refer to acc three times, all in the right-hand-side
expressions. Where is acc defined?

-jn-

On Sat, Feb 7, 2015 at 2:53 AM, 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
>



-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150207/c5153f11/attachment.html>


More information about the Beginners mailing list