I am having trouble converting a list of strings from a text file to a data type I have created called Film. I will display the code below:
Inside the films.txt
"Casino Royale"
"Daniel Craig", "Eva Green", "Judi Dench"
2006
"Garry", "Dave", "Zoe", "Kevin", "Emma"
"Cowboys & Aliens"
"Harrison Ford", "Daniel Craig", "Olivia Wilde"
2011
"Bill", "Jo", "Garry", "Kevin", "Olga", "Liz"
"Catch Me If You Can"
"Leonardo DiCaprio", "Tom Hanks"
2002
"Zoe", "Heidi", "Jo", "Emma", "Liz", "Sam", "Olga", "Kevin", "Tim"
}
My Haskell code:
type Title = String
type Actor = String
type Cast = [Actor]
type Year = Int
type Fan = String
type Fans = [Fan]
type Film = (Title, Cast, Year, Fans)
main :: IO()
main = do
putStr "What is your name?: "
name <- getLine
firstdatabase <- readFile "films.txt"
putStr firstdatabase
let database = read firstdatabase :: [Film]
mainLoop database name
Any ideas on what I will have to do?
Film. Unfortunately you won't get very far withreadhere, since theReadinstances for the types you have expect literal haskell values, so you'd need a 4-tuple (with parens) in your database file with a string (with quotes), a list of strings (with brackets), an int, then a list of strings (with brackets), all separated by commas, and then you would need the entire contents of the file to be capable of being interpreted as a literal haskell list, etc etc.readdoes not make a good parser.read. Not really elegant of course, but oh well...