Adding new entry to list

Hi all I'm having a problem trying to add a new record to a list. I need to be able to add a new record to the database. My code is below, I also need to work out the total sales for everything in the Sales list. As you can see, I've tried to do it but I can't seem to work it out. type Title = String type Artist = String type Sold = Int --type Record = (Title, (Artist, Sold)) type Sales = [(Title, Artist, Sold)] testDatabase :: Sales testDatabase = [("Kids", "MGMT", 3), ("This Charming Man", "The Smiths", 5), ("Gimme Shelter", "The Rolling Stones", 7)] totalSales :: Sales -> Title -> Artist -> Sold totalSales [] title artist = 0 --totalSales ((t,a,n):testDatabase) title artist = title artist --addSale :: Sales -> Sales --addSale (Title, Artist, sold) = (title, artist, sold + 1) --newRecord :: String -> String -> Sales -> Sales --newRecord testDatabase title artist = (title, artist) ++ testDatabase --newRecordAction :: Sales -> IO() --newRecordAction testDatabase = do --putStrLn "Enter a new title: " --title <- getLine --putStrLn "Enter an artist: " --artist <- getLine --return $ newRecord title artist testDatabase getTitle :: Sales -> Title getTitle (title,_) = title printNames :: Sales -> IO() printNames testDatabase = mapM_ print testDatabase mainLoop :: Sales -> IO() mainLoop testDatabase = do putStrLn "1 - Show all tracks in database" putStrLn "2 - Exit" putStrLn "" putStrLn "Please select an option:" input <- getLine case read input of 1 -> do putStrLn "------------------" putStrLn "Show All Tracks" putStrLn "------------------" printNames testDatabase putStrLn "" mainLoop testDatabase 2 -> do return () main :: IO() main = mainLoop testDatabase Thank you, Jack -- View this message in context: http://old.nabble.com/Adding-new-entry-to-list-tp29099032p29099032.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
participants (1)
-
Mrwibbly