type UserRatings = (String,Int)
type Film = (Title, Director, Year , [UserRatings])
I am trying to use proper the printF method for the IO but i cant figure out what is going wrong. I know the problem has to do with the userRatings.
In the neo.txt there are 25 films of type Film I am trying to print them in the user interface menu that I made.
The user types main -> then his username -> then the option choice "2" and then the films are supposed to be displayed.
displayFilmsIO :: Database -> IO()
displayFilmsIO [] = putStrLn "There are no films in the database"
displayFilmsIO filmList = sequence_[printf("|%-25s| |%-65s| |%-10d| |(%s,%d) |\n") title director year [(name,rating)] | (title, director, year, [(name,rating)]) <- filmList]
mainMenu :: [Film] -> String -> IO()
mainMenu list user = do
putStrLn "What do you want to do ?(choose one of the options below)"
putStrLn "[1] Add a film to the database \n[2] View all Films \n[3] View all films that you are fan of of\n[4] View all fans of a particular film \n[5] View all the films that were released during a particular period\n[6] Be a fan of a particular film\n[7] View the average number of fans for the films starring a particular actor \n[8] View the names of actors who have co-starred in at least one film with a particular actor \n[9] Save \n[0] Exit"
putStrLn "__________________________________"
choice <-getLine
case choice of
"2" -> do
printf ("|%-25s| |%-65s| |%-10d| | %s,%d |\n") "Title" "Cast" "Year" "Fans"
displayFilmsIO list
mainMenu list user
And this is the main method. Nothing wrong with it, it compiles but just so you have more info.
main :: IO ()
main = do
films <- loadFile2
getName2 films
loadFile :: FilePath -> IO (Either ParseError [Film])
loadFile filename = do
handle <- openFile filename ReadMode
!database <- hGetContents handle
hClose handle
return $ parse films "Films" database
loadFile2 :: IO [Film]
loadFile2 = do
allFilms <- readFile "neo.txt"
let films = read allFilms :: [Film]
return films
getName2 :: [Film] -> IO ()
getName2 films = do