Advertisement
NLinker

Monads vs boilerplate

May 18th, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Go
  2. func doStuff(context Context) (err error) {
  3.     x, err := computeX()
  4.     if err != nil {
  5.       context.Errorf("Error computing x: %v", err)
  6.       return
  7.     }
  8.     err = doSomethingWithX(x)
  9.     if err != nil {
  10.       context.Errorf("Error doing something: %v", err)
  11.     }
  12.     return
  13. }
  14.  
  15. -- Haskell
  16. doStuff :: (Monad m) => ExceptT Error m a
  17. doStuff = do
  18.   x <- computeX
  19.   doSomethingWithX x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement