[Haskell-beginners] sum problem
Roelof Wobben
r.wobben at home.nl
Sat Feb 7 08:53:34 UTC 2015
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
More information about the Beginners
mailing list