how to calculate the sum of list of lists?

Help, How to calculate the sum of list of lists in Haskell? Please help me, Miranda

Hi Miranda,
How to calculate the sum of list of lists in Haskell?
What do you mean by this? What is the value of a list? If you mean sum the numbers such that [[1,2],[3,4]] = 1+2+3+4 then you are able to ask two alternative questions - how do i convert a list of lists to a list, and how do i sum a list. Both can be answered by Hoogle: http://haskell.org/hoogle/?q=%5BInt%5D%20-%3E%20Int The list of lists to a list is a bit easier so I'll leave you to solve that one :) Thanks Neil

If I understand you correctly, this should do it:
sums :: Num a => [[a]] -> a
sums l = sum [sum p | p <- l]
-Eric
On 2/5/07, Miranda Kajtazi
Help,
How to calculate the sum of list of lists in Haskell? Please help me, Miranda
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Eric Olander
-
Mark.Carroll@Aetion.com
-
Maxime Henrion
-
Miranda Kajtazi
-
Neil Mitchell