I am trying to create a menu which read the data from a textfile. But I get three errors that variable not in scope despite having at the start of the IO(). Am I not reading the txt.file properly and is the way I creating the menu wrong?
errors
Variable not in scope: spaDatabase :: [Spa]
--line of error for spaDatabase
let updatedDB = (addSpa rid br ar (read st) spaDatabase)
Variable not in scope: spaDB
Variable not in scope: updatedDB :: [Spa]
--line of error for updatedDB
2 -> putStrLn (spaListStr updatedDB) >> menu spaDB
My code
main :: IO()
main = do
contents <- readFile "spa.txt"
let spaDatabase = (read contents :: [Spa])
menu spaDatabase
putStrLn ""
where menu spaDatabase = do
putStrLn "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
putStrLn "\nPlease select an option:"
putStrLn "1: Add a new spa to the database "
putStrLn "2: Show all spa "
putStr "\nSelected option: "
putStrLn ""
option <- getLine
putStrLn "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
output :: Int -> IO ()
output option = do
case option of 1 -> do putStrLn "Enter Spa ID: "
rid <- getLine
putStrLn "Enter Spa Brand Name: "
br <- getLine
putStrLn "Enter Spa Area: "
ar <- getLine
putStrLn "Enter Spa Stars: "
st <- getLine
let updatedDB = (addSpa rid br ar (read st) spaDatabase)
putStrLn (spaListStr updatedDB)
writeFile "spa.txt" (spaListStr updatedDB)
2 -> putStrLn (spaListStr updatedDB) >> menu spaDB