importControl.Error-- A type for my example functions to pass or fail on.dataFlag=Pass|Errormain::IO()main=doputStrLn"Starting to do work:"-- The inner monad here is Either. But note that we have-- no IO ability inside of it.letresult=dox<-eitherFailurePass"Initial Thing"y<-eitherFailureError("Second Thing "++x)note("Failed the Maybe: "++y)$maybeFailurePassycaseresultofLeftval->putStrLn$"Work Result: Failed\n "++valRightval->putStrLn$"Work Result: Passed\n "++valputStrLn"Ok, finished. Have a nice day"-- Simple function that we can use to force it to error out with a Left, or-- pass with a Right value. It just includes some helper text as its content,-- showing what happened.eitherFailure::Flag->String->EitherStringStringeitherFailurePassval=Right$"-> Passed "++valeitherFailureErrorval=Left$"-> Failed "++val-- Simlar to eitherFailure, but return a (Just String) or a Nothing based on-- if we told it to fail.maybeFailure::Flag->String->MaybeStringmaybeFailurePassval=Just$"-> Passed maybe "++valmaybeFailureError_=Nothing
You can see it’s the same code, except the result in main is calculated
directly there, rather than calling another function.
Note that this isn’t the transformer library, so you can’t be clever and do
stuff like lift and friends to do IO in that Either workflow.