For the following code, I am getting a parse error on input 'else' for line 33 (the third 'else' in the code) when I try to compile. How can I fix this?
import Control.Monad
import System.Directory
import System.IO
import System.FilePath.Posix (takeDirectory)
import System.Environment
main :: IO ()
main = do
let loop = do
let cmd = 'x'
-- take directory name --
print "Enter Directory Name "
dir <- getLine
-- check whether directory exist or not
check <- doesDirectoryExist dir
if check == True
then do
ipt <- getLine -- take command
let cmd = take 1 ipt
if cmd == "l"
then do
contents <- listDirectory dir
print contents
else
if cmd == "r"
then do
let index = drop 1 ipt
else
if cmd == "a"
then
let info = drop 1 ipt
else
putStrLn (cmd ++ "Invalid Command")
else putStrLn "Directory not Exist"
when ( cmd /= 'x' ) loop -- if command equals to x end the loop
loop
Aucun commentaire:
Enregistrer un commentaire