If only one method saveStuffcan be successful, then a type that is isomorphic Maybe ErrorMessageis the right type. Maybe ErrorMessageItself has a flaw, which usually Nothingmeans a failure to use Maybe, so it will contradict the expectations here. As for this, Either ErrorMessage ()it is better, but the parameter ()for the case Rightdoes not carry any information, so this parameter also does not have elegance.
If you do not want to accept these shortcomings, define your own type of result
data Result = Success | Failure ErrorMessage
-- with type ErrorMessage = String, for example
source
share