I have a list xxs and I need to create a new one that adds and sums elements from the old list.
Let me draw it to demonstrate:

So, I have the list:
xxs = [("a","b", [(1,"a","b"),(2,"a","b")]), ("c","d",[(3,"a","b"),(4,"a","b")])]
My best approach so far is:
infoBasicas = [ (x,y,aux) | (x,y,_) <- xxs]
where aux = sum [ z | (_,_,ys) <- xxs, (z,_,_) <- ys]
Output:
[("a","b",10),("c","d",10)]
Although I’m not far away… I’m not quite there yet and would really appreciate some suggestions.
The problem with you solution is that
auxis the same for each element ofxxs. when you write(x,y,_) <- xxs, you are throwing away the list with the numbers you want to sum. Instead, keep that list, working one element at a time, so:To find the sum of the
innerLists, you only want the numbers, so you can throw them away. After that is done, you are left with a list of numbers, which can just be summed with the standardsumfunction:Not that we are using
fst3here, instead offst, as these are triples, not pairs.