Reputation: 923
main :: IO ()
main = do
contents <- readFile "text.txt"
let database = (read contents :: [Film])
putStr "Please enter your username: "
userName <- getLine
menu database
where menu newDb = do putStrLn "\nPlease select an option:"
putStrLn "1: Display all films currently in the database"
putStrLn "2: Add a new film to the database"
putStrLn "3: Search for films by director"
putStrLn "5: Exit"
putStr "\nSelected option: "
option <- getLine
case option of
"1" -> putStrLn(formatDatabase newDb)
"2" -> do putStr "Name of film: "
title <- getLine
putStr "Name of director: "
director <- getLine
putStr "Year of release: "
year <- getLine
putStrLn(formatDatabase $ addFilm title director (read year) [] newDb)
"3" -> do putStr "Name of director: "
director <- getLine
putStrLn $ formattedByDirector director
menu newDb
Returns error:
Parse error in pattern: putStr
On the line: "2" -> do putStr "Name of film: "
Upvotes: 1
Views: 473
Reputation: 550
Please do not indent your code in the manner found in many textbooks. It looks nice on paper, but is terrible for actually working with.
Here's a much more sane style guide: https://github.com/tibbe/haskell-style-guide
Upvotes: 0
Reputation: 183968
You must indent the lines in the do
block all to the level of the first token after the do
. The same applies to the case 3.
case option of
"1" -> putStrLn(formatDatabase newDb)
"2" -> do putStr "Name of film: "
title <- getLine
putStr "Name of director: "
director <- getLine
putStr "Year of release: "
year <- getLine
putStrLn(formatDatabase $ addFilm title director (read year) [] newDb)
"3" -> do putStr "Name of director: "
director <- getLine
putStrLn $ formattedByDirector director
Upvotes: 5