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

Simplify Monad #69

Open
Lysxia opened this issue Sep 25, 2019 · 6 comments
Open

Simplify Monad #69

Lysxia opened this issue Sep 25, 2019 · 6 comments
Labels

Comments

@Lysxia
Copy link
Contributor

Lysxia commented Sep 25, 2019

Original title: Use single-method class for Monad

Proposal: put bind and ret into their own classes, and let Monad be a dummy class indexed by those two:

Class Bind m := bind : forall a b, m a -> (a -> m b) -> m b.
Class Return m := ret : forall a, a -> m a.  (* And some are starting to prefer "pure" to "return" in Haskell *)
Class Monad m `{Bind m} `{Return m} := {}.
Instance MonadWith m `{Bind m} `{Return m} : Monad m := {| |}.

That way, bind and ret don't simplify away when used with concrete monads. This also allows ret to be shared with Applicative, since of course I am extending my proposal to all multi-field classes.

@Lysxia
Copy link
Contributor Author

Lysxia commented Sep 25, 2019

Another alternative is to prevent bind and ret from simplifying, which solves that one problem, but not the one about sharing identifiers. More generally, it's kind of an arbitrary choice to bundle a certain set of methods together in a record, while indexed classes make it easier to mix and match.

@Lysxia
Copy link
Contributor Author

Lysxia commented Sep 26, 2019

On a related note, what's the purpose of PMonad again?

@gmalecha
Copy link
Collaborator

PMonad was introduced to allow for talking about well-formed types without needing to introduce axioms such as functional extensionality. It was never used extensively and is a good candidate for removal.

On the ret and bind, my only worry with this is terms will get much larger. Rather than simply forall m : Type -> Type, Monad m -> .... you will end up with forall (m : Type -> Type) (rm : Ret m) (bm : Bind m), Monad m rm bm -> ... which can be a lot of extra type checking and a lot of places where resolution can (potentially) get confused. Also, Ret isn't a very good typeclass name. I believe that it is usually called Pointed or something like that.

@gmalecha
Copy link
Collaborator

One other thing, I get the impression that there are some users of ExtLib and this change would be a breaking change. We should ensure that if we do this, that we bump the major version number and leave the old packages in Opam (possibly also maintaining them for a little while depending on interest).

@Lysxia
Copy link
Contributor Author

Lysxia commented Oct 13, 2019

I've experimented with this a bit and I have to agree that unbundling the Monad class like that makes things too heavyweight.

If we can drop PMonad that would also be great.

@Lysxia Lysxia changed the title Use single-method class for Monad Simplify Monad Oct 13, 2019
@gmalecha
Copy link
Collaborator

I think dropping PMonad is a good idea, we really need a better notion of equivalence in Coq otherwise most of these things are too painful.

@github-actions github-actions bot added the Stale label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants