
Hi, I have got a database with movies added into it. What Im basically coding is: - add a new film to the database - display all the films - display all the films by a given director - display a list of user ratings (together with the users' names) for a given film - show the average overall rating for a given director - allow a given user to rate (or re-rate) a film (note that only the latest rating from the user should remain recorded) - display all the films from a given year, sorted in descending order of overall rating Now I want to allow a given user to rate or be able to re-rate a film. But the latest rating from the user should remain recorder tho..and also I want to display all the films that a given user likes (i.e. the films to which she has given a positive-valued rating). I have written the code for the user liking the film but it doesn't seem to work and i'm not sure what to do with that one eiher. Below is the coding that I've written so far, but i'm stuck on the last bit which I can't seem to code. type Director = String type Title = String type Year = Int type Mark = Int type Rating = (String, Int) type Film = (Title, Director, Year, [Rating]) type Database = [Film] testDatabase :: Database testDatabase = [("Casino Royale", "Martin Campbell", 2006, [("Garry",-8),("Dave", 0)]), ("Blade Runner", "Ridley Scott", 1982, [("Amy",5)]), ("The Fly", "David Cronenberg", 1986, [("Fred",7)]) ] addFilm :: Database -> Title -> Director -> Year -> Database addFilm database title director year = (title, director, year, []): database displayFilms :: Database ->[(Title, Director, Year, Mark)] displayFilms [] = [] displayFilms ((i, j, k, l):xs) |l == [] = (i, j, k, 0) : displayFilms xs |otherwise = (i, j, k, overallRating l) : displayFilms xs overallRating :: [Rating] -> Int overallRating rating = div (sum [j | (_,j) <- rating]) (length rating) filmsByDirector :: Database -> Director -> Database filmsByDirector [] filmDirector = [] filmsByDirector((i, j, k, l):xs) filmDirector |j == filmDirector = (i, j, k, l) : filmsByDirector xs filmDirector |otherwise = filmsByDirector xs filmDirector filmRating :: Database -> Title -> [Rating] filmRating [] filmRat = [] filmRating ((i,j, k, l):xs) filmRat |i == filmRat = (l ++ filmRating xs filmRat) |otherwise = filmRating xs filmRat THIS DOESNT SEEM TO WORK? {- filmsLiked :: Database -> String -> Database filmsLiked [] user = [] filmsLiked ((i,j,k,l):xs) user | == user = i ++ filmsLiked xs user |otherwise = filmsLiked xs user person :: [Rating] -> String -> Bool person [] userName = False person ((n, s):xs) userName |n == userName && s > 0 = True |otherwise = person xs userName -} averageDirector :: Database -> Director -> Int averageDirector [] directorRating = 0 averageDirector ((i,j,k,l):xs) directorRating |j == directorRating = (overallRating l) + (averageDirector xs directorRating) |otherwise = averageDirector xs directorRating filmFromYear :: Database -> Year -> Database filmFromYear [] filmYear = [] filmFromYear ((i,j,k,l):xs) filmYear |k == filmYear = (i,j,k,l) : filmFromYear xs filmYear |otherwise = filmFromYear xs filmYear rateFilm :: [Rating] -> Rating -> [Rating] rateFilm [] rating = rating:[] rateFilm ((user, rating):xs) (newUser, newRating) |newUser == user = ((newUser, newRating):xs) |otherwise = (user, rating) : (rateFilm xs (newUser, newRating)) Stuck on this bit.. {- changeFilm :: Database -> Title -> [Rating] -> Database changeFilm ......... -} Any help is appreciated..thank you! _________________________________________________________________ http://clk.atdmt.com/UKM/go/195013117/direct/01/ We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now