I am new to Haskell and currently learning about lists.
I have a list of marks
[("Tom", 87, 78, 67), ("Dick", 56, 45, 72)]
and I need to get the sum of marks and the average of it. This is my approach.
Create a function to calculate list of sum of marks of each candidate
sumOfMarks = (\(a, b, c, d) -> b + c + d)
and map that function to the original list
newList = map sumOfMarks [("Tom", 87, 78, 67), ("Dick", 56, 45, 72)]
create a function to calculate list of average of marks of each candidate
avgList = map (`div`3) newList
merge all the lists original, newList and avgList
Desired output is
finalList = [("Tom", 87, 78, 67, 232, 77.34), ("Dick", 56, 45, 72, 173, 57.67)]
Another question is - whether this is the best approach to solving the problem and is there a better way?