Proposal: add laws to MonadError

Alexandre Esteves alexandre.fmp.esteves at
Fri Sep 9 21:42:36 UTC 2022

I ran into a scenario where the use of MonadError would only be valid if
  catchError (pure a) h = pure a
was a law, so I looked up the laws in
but surprisingly found none.

One would expect to see
  1. catchError (pure a) h = pure a
  2. catchError (throwError e) h = h e
  3. throwError e >>= f = throwError e

which would rule out silly instances like
  instance MonadError () Maybe where
    throwError ()        = Nothing
    catchError _ f = f ()

Searching for "monad error laws" gives me no haskell results, only which
suggests the same laws.

I propose adding these 3 laws to MonadError haddocks.
AFAICT the IO/Maybe/Either/ExceptT instances in
all obey the laws.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list