I want to write a function saveStuff
that saves something to a file, after it passes certain tests. If tests fail, I need to raise an error. What should be the result type of this function? I thought of IO (Either String ())
and IO (Maybe String)
, but both of them feel wrong for some reason. I looked up similar functions from standard library, but they simply seem to return IO ()
. They throw exceptions on failures. I can't find myself liking that approach.
You could consider writing something that returns an ErrorT String IO ()
. Documentation for the ErrorT
monad transformer is on Hackage. There are more suggestions in the excellent Eight Ways to Report Errors by Eric Kidd and the follow up some years later by Edward Yang.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With