Advertisement
NLinker

Include third-party library into our ExcepT monad

Jun 19th, 2017
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import           Control.Monad.Except (ExceptT(..), throwError)
  2.  
  3. data Error = MyError | ThirdPartyError String
  4.  
  5. -- some third-party function, that doesn't return our type
  6. doSomethingWithX :: Integer -> Either String ()
  7. doSomethingWithX = undefined
  8.  
  9. computeX :: (Monad m) => ExceptT Error m Integer
  10. computeX = undefined
  11.  
  12. doStuff :: (Monad m) => ExceptT Error m ()
  13. doStuff = do
  14.   x <- computeX
  15.   lift3rdParty $ doSomethingWithX x
  16.  
  17. lift3rdParty :: (Monad m) => Either String t -> ExceptT Error m t
  18. lift3rdParty = either (throwError . ThirdPartyError) return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement