I think I lack a basic understanding of monad transformers because I found myself writing this code:
import Control.Monad.Identity
import Control.Monad.Error
liftError :: Either String Int -> ErrorT String Identity Int
liftError x = do case x of
Right val -> return val
Left err -> throwError err
gateway :: Bool -> ErrorT String Identity Int
gateway = liftError . inner
inner :: Bool -> Either String Int
inner True = return 5
inner False = throwError "test"
While this works, I think it can be done more elegantly. In particular, I am looking for a replacement liftError, which, I think, I do not need to determine for myself.
What is the easiest way to make gatewayand innerwork together without changing their type?
source
share