
Sebastian Fischer wrote:
using Control.Monad.Error:
either (hPutStrLn stderr) return =<< runErrorT $ do d1x <- lift $ doesDirectoryExist d1 unless d1x $ fail "Directory " ++ d1 ++ " not found." f1x <- lift $ doesFileExist (d1 > f1) unless f1x $ fail "File " ++ f1 ++ " not found." d2x <- lift $ doesDirectoryExist d2 unless d2x $ fail "Directory " ++ d2 ++ " not found." f2x <- lift $ doesFileExist (d2 > f2) unless f2x $ fail "File " ++ f2 ++ " not found." lift $ doStuff d1 d2 f1 f2
So... essentially, run the ErrorT transformer on top of IO to do the error handling? That seems like a much nicer solution - if I can get it to work. (In general, any code involving monad transformers tends to fail with elaborate type checker failures. Typically it takes me hours to figure out why... Maybe somebody has written a tutorial on this stuff?)