I have a function that handles errors via Either
:
funErrViaEither :: a -> Either SomeException b
I want to use this function in another function that should be more flexible and return MonadThrow m
:
funErrViaThrow :: MonadThrow m => a -> m b
funErrViaThrow x =
if x = someCondition
then funErrViaEither
else throwM (SomeException MyCustomException)
This does not compile; the type checker complains that the return type of funErrViaEither
does not match the expected type m b
. I don't understand why - Either
has an instance of MonadThrow
with SomeException
as the type of Left
.
Where do I err? What would be the correct way to convert an error signalled via Either
into one signalled via MonadThrow
?