Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6959413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:16:08+00:00 2026-05-27T15:16:08+00:00

I have a list xxs and I need to create a new one that

  • 0

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:

visualization of list transformation

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:16:09+00:00Added an answer on May 27, 2026 at 3:16 pm

    The problem with you solution is that aux is the same for each element of xxs. 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:

    infoBasicas = [(x, y, doSum innerList) | (x, y, innerList) <- xxs]
    

    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 standard sum function:

    doSum list = sum (fst3 list) -- There is one small error here. Can you see what it is?
    fst3 (a, _, _) = a
    

    Not that we are using fst3 here, instead of fst, as these are triples, not pairs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list. I need to create a a new list, like in
Several times I've wanted to traverse a list and pick out elements that have
I have a list of elements and I wish to update them: from this:
I wanna create a function that have the type int -> 'a list ->
I have list of structure. I want to modify a particular data from the
i have list of rows that user select and i want to delete them,
I have List with n items. I wish transform my list to new list,
I have list with items having two textview and one imageview.I inflate the list
let undefined = [string; ; string; boolean;;innermost] I have a list and I want
Write a function that counts the number of elements in the list that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.