Why “Empty do” error when my do isn't empty?

后端 未结 3 1528
野的像风
野的像风 2021-01-29 09:38

I am trying to create a menu which gives output based on user input. However, I get a empty do error even though I have code for it to do underneath it. Am I missing something?<

3条回答
  •  礼貌的吻别
    2021-01-29 09:58

    Try this:

    main :: IO()
    main = do 
           contents <- readFile "spa.txt"
           let storage = (read contents :: [Spa])
           putStrLn "Please Enter Your Name: "
           name <- getLine
           putStrLn ""
           putStrLn ("Welcome " ++ name)
           menu storage
           putStrLn "" where
                menu resDB = do
                    putStrLn "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 
                    putStrLn "\nPlease select an option:"
                    putStrLn "1: Add a new spa to the database "
                    putStrLn "2: Show all spas in the database"
                    putStrLn "3: Give all spas operating in a certain area"
                    putStrLn "4: Give all spas that have a performance of 8 or higher "
                    putStrLn "5: Give the average performance for the spas in a certain area "
                    putStrLn "6: Give the names of the spas a given supervisor has rated the service level, along with that rating result for each spa."
                    putStrLn "7: Give the names of the spas a given supervisor has yet to rate the service level, along with that spa performance."
                    putStrLn "8: Allow a given chef rating to be entered (or updated) for a restaurant he has rated (note that only the latest result from the supervsior should remain recorded)"
                    putStrLn "9: Exit"                      
                    putStr "\nSelected option: "
                    putStrLn ""
                    option <- getLine    
                    putStrLn "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    
                output :: Int -> IO ()
                output option = do 
                    case option of
                        1 -> putStrLn "Enter Spa ID: "
    
    

提交回复
热议问题