1
我有一個問題,弄清楚爲什麼編譯代碼時我得到一個分析錯誤。我嘗試使用製表符和空格縮進,但沒有成功。也許我只需要在代碼上另設一個眼睛,任何幫助將不勝感激!Haskell格式化I/O錯誤
的錯誤似乎是從這一行來:
putStrLn 「\ nSelected選項:」
main :: IO()
main = do contents <- readFile "films.txt";
let database = (read contents :: [Film])
putStrLn "Please enter your name:";
name <- getLine;
putStrLn ("Hello " ++ name ++ "!");
menu database
where menu newDb = do putStrLn "\nWhat would you like to do?";
putStrLn "1 -> Add a film";
putStrLn "2 -> Display all films";
putStrLn "3 -> Display all films by director's name";
putStrLn "4 -> Display the films of an average website rating";
putStrLn "5 -> Display the average rating of the films of a particular actor";
putStrLn "6 -> Show the films you have rated, with the rating";
putStrLn "7 -> Rate or ReRate a film";
putStrLn "8 -> Display films released during or after a year, sorted in descending order of rating";
putStrLn "9 -> Exit & Save";
putStrLn "\nSelected option: "
option <- getLine
case option of
"1" -> do putStr "Name of Film: "
title <- getLine
putStr "Name of the Director: "
director <- getLine
putStr "Year the film was released: "
year <- getLine
putStrLn (map formatFilmOutput $ addFilm title director (read year) [] newDb)
"2" -> do putStrLn (displayAllFilm newDb) >> menu newDb
我得到一個不同的錯誤,當我嘗試,它的上線'標題< - getLine'。你碰巧在你的編輯器中使用了標籤嗎? Haskell允許混合它們,但是標籤不一定像你在編輯器中看到的那樣被解析。 – bheklilr
是的,我可以在幾行上使用空格。只是再次測試它,當註釋掉一切似乎都很好,但是當添加解析錯誤時會再次出現。 – user3411002
查找編輯器中用空格替換製表符的設置。我保證它會讓事情變得更簡單。它就像Python一樣,可以使用選項卡,但人們最終會遇到解析錯誤。 – bheklilr