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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:55:40+00:00 2026-06-03T03:55:40+00:00

I am trying to modify an element in the list in the database to

  • 0

I am trying to modify an element in the list in the database to add to ratings, I want to return a modified database with the new element in it. I understand Haskell has immutable things but at the same time I can’t quite grasp how to do it.

Here are the types:

data Film = Film Director Title Year Ratings
     deriving (Show,Ord,Eq, Read)

testDatabase :: [Film]

The only code I have is:

--addRating :: Rating -> Film -> Film
--addRating rating (Film name director year ratings)= (Film name director year [(ratings : rating)])


--findFilm name = head $ filter (\(Film n _ _ _) -> n == name) testDatabase 

The find film works well but I can’t get the addRating to work, even if it did work I still don’t understand how to mesh it all together to have a function to call to return a list of Film that has the element with the new ratings on it.

  • 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-03T03:55:42+00:00Added an answer on June 3, 2026 at 3:55 am

    You almost had it correct:

    addRating rating (Film name director year ratings)
        = (Film name director year [(ratings : rating)])
    

    At the moment you have the code:

    [(ratings : rating)]
    

    The : operator has type a -> [a] -> [a], it takes one element and appends it to the start of the list, not the end of the list, so you need to switch your arguments around.

    Also, the syntax [x], when used like you have, creates a list consisting of one element. If you use it here it will take the list you have created and wrap it inside another list, which is not what you want.

    You just need to make a list consisting of the rating prepended to the rest of the ratings:

    (rating : ratings)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify the class of an element if an ajax call based
I am trying to modify a stored procedure ( adding a new column in
I am trying to modify the way a category list is drawn on the
I am taking the value of a select element and trying to modify it
Possible Duplicate: Detect element content changes with jQuery I am trying to modify the
I'm trying to modify redactor 's image_edit and image_save methods to add some functionality.
I'm trying to modify the HTML markup of a page in order to add
I am trying to use focus event on list element. it's working with hover,
I'm trying to write a recursive function that return a List < int *
I'm trying to modify a name-related element. I'm taking values from a drop-down and

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.