MonadError section in “All about monads”

前端 未结 1 1592
轻奢々
轻奢々 2021-01-21 15:12

I\'m now really confused about the Error monad in which \"All about monads\" describes.

It claims the definition of Error monad as

class (Monad m) =>          


        
相关标签:
1条回答
  • 2021-01-21 15:47

    It's just a typo, the instance should be

    instance MonadError e (Either e) where
      throwError = Left
      (Left e) `catchError` handler = handler e
      a        `catchError` _       = a
    

    with two type parameters, as you expected.

    Either e is the monad, and e is the corresponding error type.

    0 讨论(0)
提交回复
热议问题