I want to extract the values out of the monad but i can't figure out ,how can i do that?
The problem is in available
function.
There are already few answers but here i have specific question about an extra function which only tries to get value from IO monad.
main2 = do
fileName <- getLine
case (available fileName) of
False -> "Could not find the file"
True -> withFile fileName ReadMode (\handle -> do
contents <- hGetContents handle
putStrLn $ "Enter the name of second file"
secondName <- getLine
case (available fileName) of
False -> "could not find second file"
True -> withFile secondName AppendMode (\secondHandle -> do
hPutStrLn secondHandle contents
putStrLn $ "Done, copying file"))
Here is my available function and i want simple True
or False
.
I think i can't do pattern matching with IO
and also can't figure out how do i get simple True
or False
?
available :: FilePath -> Bool
available fileName = case (doesFileExist fileName) of
IO True = True
IO False = False