Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add laws for MonadError and add tryError #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lysxia
Copy link

@Lysxia Lysxia commented Mar 4, 2019

tryError is used to state an additional law about the interaction of catchError with (>>=).

For reference, the 5 laws other than that one can be found in the paper Just do it: Simple Monadic Equational Reasoning, Section 5 (modulo a change from catch :: m a -> m a -> m a to catchError :: m a -> (e -> m a) -> m a).

@Lysxia
Copy link
Author

Lysxia commented Mar 4, 2019

I also cut the original comment on this class. I find the first sentence quite hard to read, and the rest is not quite relevant.

It is common to use Either String

IMO Either is a very niche instance of MonadError.

You can also define your own error type and/or use a monad type constructor
other than @'Either' 'String'@ or @'Either' 'IOError'@.
> In these cases you will have to explicitly define instances of the 'MonadError'
> class.

You don't need to define additional instances if you just want to vary your exception type from String or IOError (I would assume this is a remnant of the old MonadError).

(If you are using the deprecated "Control.Monad.Error" or "Control.Monad.Trans.Error", you may also have to define an 'Error' instance.)

The old MonadError has been deprecated for so long, I would assume people who have to maintain such old code should be able to follow the changelog.

@Lysxia
Copy link
Author

Lysxia commented Mar 4, 2019

See #5 . With #61, the remaining effects to document are Writer and Cont.

@Lysxia
Copy link
Author

Lysxia commented Mar 4, 2019

Please also note that everything I'm doing here is open for questions and discussion.

@Lysxia Lysxia force-pushed the laws-except branch 2 times, most recently from 58262b1 to 5e2b736 Compare March 4, 2019 17:32
@Lysxia
Copy link
Author

Lysxia commented Mar 4, 2019

This probably needs a @since annotation but I don't know what version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant