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

ApplicativeReader #35

Open
lpsmith opened this issue May 22, 2016 · 2 comments
Open

ApplicativeReader #35

lpsmith opened this issue May 22, 2016 · 2 comments
Milestone

Comments

@lpsmith
Copy link

lpsmith commented May 22, 2016

The Monad constraint on MonadReader is a bit too constraining for me; I'd really like to loosen that constraint to Applicative (or looser?) while breaking the least amount of code possible.

So now that we've made Applicative a superclass of Monad, that would make such a transition considerably easier. However, simply changing Monad to Alternative, while it shouldn't break instances, would break client code that use the Monad class but don't explicitly declare (Monad m, MonadReader m) =>.

It seems fairly safe to assume there's more client code than there are instances, one possibility would be to have something like the following:

class Applicative m => ApplicativeReader r m | m -> r where
    ask :: ...
    local :: ...
    reader :: ...

class (Monad m, ApplicativeReader m) => MonadReader m
instance (Monad m, ApplicativeReader m) => MonadReader m

Then, the only thing people would have to do would be to replace the name MonadReader with ApplicativeReader in all their instances. This might cause some problems for people who don't update their instances and have have OverlappingInstances turned on; it would seem preferable to make MonadReader a closed typeclass or a typeclass synonym.

Making MonadReader a typeclass synonym is possible with ConstraintKinds, but would also require ConstraintKinds to be enabled in all code that mentions the MonadReader constraint.

@chessai
Copy link
Member

chessai commented Jun 25, 2019

Alternatively, how much breakage would be caused by changing the constraint, to the following?:

class Applicative m => MonadReader r m | m -> r where {...}

Also, in transformers, a lot of constraints can be relaxed to Applicative.

This is all post-AMP, of course.

@ekmett
Copy link
Member

ekmett commented Oct 18, 2020

I think I place this in the bin of ideas for a major mtl 3 rewrite. The major concern I have is that when you go to state laws for the transformers, many of them cannot be stated for the Applicative-only form.

@chessai chessai added this to the MTL 3 milestone Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants