Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be the result type of this function?

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.

like image 373
missingfaktor Avatar asked May 04 '12 22:05

missingfaktor


1 Answers

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.

like image 68
Daniel Wagner Avatar answered Nov 15 '22 12:11

Daniel Wagner