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.
I want to write a function saveStuff that saves something to a file, after
Share
You could consider writing something that returns an
ErrorT String IO (). Documentation for theErrorTmonad 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.