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 8203401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:32:33+00:00 2026-06-07T07:32:33+00:00

Hi could you please help me on how to increment the last element of

  • 0

Hi could you please help me on how to increment the last element of a tuple.
Currently i have this list of tuples

items :: [Grocery]
items = [("Water", "Drink Section", 1),
         ("Squash", "Drink Section", 1),
         ("Apple", "Fruit Section", 1),
         ("Plates", "Disposable Section", 1),
         ("Plates", "Ceramic Section", 1)]

and what i wanted to do is increment it by 1 every time the item is bought and output the database. currently i have this

sales:: [database] -> String -> String-> [database]
sales db itemName sectionName = []
sales ((item, section, qty): xs) itemName sectionName 
     | item == itemName && section== sectionName = [(item, section, qty + 1)]
     | otherwise = []

im still in the bit of incrementing it and im stuck. please help me i’m still a newbie on this language. thank you!

Edit

its all working now but how do you output the rest of the list? i tried recordSale xs trackArtist trackTitle but when i test it the old record that i incremented gets printed as well instead of getting modified? lets say that i incremented apple what it’ll print is this

[("Apple", "Fruit Section", 2),("Water", "Drink Section", 1),("Squash", "Drink Section", 1), ("Apple", "Fruit Section", 1)]

it duplicates the record instead of just adding 1

  • 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-06-07T07:32:35+00:00Added an answer on June 7, 2026 at 7:32 am

    That’s not bad, but lets pretend you’re trying to increment “Squash”, the second element down in your example list of items. What does sales do? It checks if the first item in the list, Water, equals Squash. Since water doesn’t equal squash it hits the otherwise case and returns [].

    So all of that seems right up until we got a [] back – lets change the code in otherwise. Obviously we don’t want to throw away the entire list, that would be stupid. You should rewrite it to keep the item that was just compared and concatenate it on to the result of sales applied to the rest of the list (xs).

    After you get that otherwise branch fixed you’re going to notice the entire list after the item you increment is thrown away – I think that one will pop right out at you once you finish this issue.

    P.S. Fire the employee that put Squash in the drinking section.

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

Sidebar

Related Questions

Could anyone please help me convert this code to vb.net, I have tried it
Could you please help me converting this c++ code into python: I am trying
Could someone please help me to convert this String into a Map ... String
Could somebody please help me get Clang up and running? (I don't have 3.2)
Could someone please help explain why I can't get this to work? I properly
Could you please help me with this one: In one of my scripts I
Was wondering if somebody could please help me solve this. I've follwed all steps
Could someone please help me out with the following problem in java. I have
I wonder if anyone could please help me I have been using HTML tidy
Could you please help me out to find the correct deceleration rate for the

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.