-
Notifications
You must be signed in to change notification settings - Fork 53
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
Correct the Applicative & MonadFix instances for ErrorC #228
Conversation
It was previously incorrect in that `throwError e <*> a` would diverge when `a` diverged, but `throwError e \`ap\` a` would not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for review.
newtype ErrorC e m a = ErrorC { runErrorC :: m (Either e a) } | ||
deriving (Functor) | ||
newtype ErrorC e m a = ErrorC { runErrorC :: ExceptT e m a } | ||
deriving (Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadTrans) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining ErrorC
atop ExceptT
simultaneously fixes the unlawful Applicative
instance and allows us to remove a great number of hand-written instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also fixes the divergent MonadFix
instance.
|
||
instance Alternative m => Alternative (ErrorC e m) where | ||
empty = ErrorC empty | ||
instance (Alternative m, Monad m) => Alternative (ErrorC e m) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still define our own Alternative
and MonadPlus
instances in order to retain our existing semantics instead of adopting ExceptT
’s (which handles them itself using a Monoid
constraint on e
instead of passing them along to m
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave this as documentation in the file? Haddocks on those instances, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant. One small thing, but this is ready to go once it’s fixed.
It was previously incorrect in that
throwError e <*> a
would diverge whena
diverged, butap (throwError e) a
would not.