if
in Haskell must always have a then
and an else
. So this will work:
action = do
isdir <- doesDirectoryExist path
if not isdir
then handleWrong
else return ()
doOtherActions
Equivalently, you can use when
from Control.Monad:
action = do
isdir <- doesDirectoryExist path
when (not isdir) handleWrong
doOtherActions
Control.Monad also has unless
:
action = do
isdir <- doesDirectoryExist path
unless isdir handleWrong
doOtherActions
Note that when you tried
action = do
isdir <- doesDirectoryExist path
if(not isdir)
then do handleWrong
else do
doOtherActions
it was parsed as
action = do
isdir <- doesDirectoryExist path
if(not isdir)
then do handleWrong
else do doOtherActions