this is for pretty important assignment and has been driving me up the wall all evening, simply cannot fix. Really appreciate any help...
I have a list (database) of "tracks" (of music records) - tuples of (Title, Artist, SalesNumber) and my task is to increment a sale of a given track if it is already present in the database (same title and artist) and just increment by 1 to sales number, or if is not already present, to add it to the database. I have written - I think correctly - functions to perform either of these tasks however am struggling to write the function which determines whether adding a new record or simply incrementing it and to call either.
addNewTrack :: [Sale] -> Title -> Artist -> [Sale]
addNewTrack testDatabase title artist = testDatabase
incrExistingTrack :: [Sale] -> Title -> Artist -> [Sale]
incrExistingTrack testDatabase testedTitle testedArtist = []
incrExistingTrack ((title, artist, salesNumber): xs) testedTitle testedArtist
| testedTitle == title && testedArtist == artist =
[(title, artist, salesNumber + 1)]
| otherwise = incrExistingTrack xs title artist
recordSale :: [Sale] -> Title -> Artist -> [Sale]
recordSale testDatabase title artist
let trackExists = sameTrack title artist
if trackExists == True
then incrExistingTrack title artist
else addNewTrack title artist
sameTrack :: Title -> Artist -> Sale -> Bool
sameTrack queriedTitle queriedArtist (title, artist, salesNumber)
| (queriedTitle == title) && (queriedArtist == artist) = True
| otherwise = False
The question - What is wrong with the if statement in my recordSale function to give "parse error (possibly incorrect indentation or mismatched brackets)" on the first character of the fourth line of the fucntion?
recordSale :: [Sale] -> Title -> Artist -> [Sale]
recordSale testDatabase title artist
let trackExists = sameTrack title artist
if trackExists == True
then incrExistingTrack title artist
else addNewTrack title artist
I have been shifting things around and changing indents for so long to no avail and I desperately need this to work ASAP for my degree, I am sure it must be a very simple error, would be massively appreciated if someone could identify this and / or provide an alternative and possibly more elegant implementation of what im trying to do!
Thank you!
Aucun commentaire:
Enregistrer un commentaire