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

Should Validation be a Selective transformer? #54

Open
turion opened this issue Jun 23, 2022 · 2 comments
Open

Should Validation be a Selective transformer? #54

turion opened this issue Jun 23, 2022 · 2 comments

Comments

@turion
Copy link
Collaborator

turion commented Jun 23, 2022

Either naturally generalises as a monad transformer, ExceptT, and we've recently established that this is a bona fide Selective transformer, meaning that there is a natural instance Selective f => Selective (ExceptT e f). I wonder whether there is also such an instance for

newtype ValidationT e f a = ValidationT { runValidationT :: f (Validation e a) }

The obvious question is whether this has the same Selective instance like ExceptT would have. I believe the instances of Either e and Validation e are isomorphic. But for a selective transformer, we probably also demand that lift :: f a -> ValidationT e f a defined by Validation . fmap Success should be a Selective morphism, and that law should be checked.

If this all works out, then maybe it makes sense to simply rename Control.Selective.Trans.Except to Control.Selective.Trans.Validation.

@snowleopard
Copy link
Owner

I think you are right that we can define ValidationT but the instance will probably be different: EitherT usually short-circuits the computation on the first failure, whereas Validation aggregates errors using the supplied Semigroup e.

@turion
Copy link
Collaborator Author

turion commented Jun 24, 2022

Ah, so the Applicative instances are different! Good point. Interesting, so ValidationT e m and ExceptT e m will be isomorphic as functors and as selectives, but not as applicatives. And yet the Selective instance will probably satisfy the compatibility laws with the Applicative instance (I'm just assuming this based on your Coq proof for Validation e). Yet another way how selectives can be subtly different.

@turion turion mentioned this issue Jun 24, 2022
1 task
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

No branches or pull requests

2 participants