NLinker icon

Include third-party library into our ExcepT monad

NLinker | PRO | 06/19/17 08:55:22 AM UTC | 0 ⭐ | 919 👁️ | Never ⏰ | []
Haskell |

560 B

|

None

|

0 👍

/

0 👎

import           Control.Monad.Except (ExceptT(..), throwError)
 
data Error = MyError | ThirdPartyError String
 
-- some third-party function, that doesn't return our type
doSomethingWithX :: Integer -> Either String ()
doSomethingWithX = undefined
 
computeX :: (Monad m) => ExceptT Error m Integer
computeX = undefined
 
doStuff :: (Monad m) => ExceptT Error m ()
doStuff = do
  x <- computeX
  lift3rdParty $ doSomethingWithX x
 
lift3rdParty :: (Monad m) => Either String t -> ExceptT Error m t
lift3rdParty = either (throwError . ThirdPartyError) return

Comments