-
Notifications
You must be signed in to change notification settings - Fork 1
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
Generic infix operators? #10
Comments
Yeah, do you want to submit a PR for it? If you write the code, I can do the tests and documentation. Are you planning to implement other monads in your package or is it only generics and operators? I agree that a unified package would be good to have, but it would likely only appeal to users who have a background in other FP languages. {maybe} is an attempt to make the syntax as familiar as possible to R/tidyverse programmers. |
Sounds good. I'll see what I can put together. It'll also be a bit of a learning experience with S7. What do you think about the dependency structure? I assume it should be With {monad} I started off thinking I would include some implementations too, but now I'm leaning towards just having it be the generic operators. Then implementing classes in other packages could either add optional support (requiring users to explicitly load the operators), or built-in support by re-exporting the operators. Especially with the sum types it's nice to have a dedicated namespace. Like for example |
Now that I've thought a bit more, wouldn't it make more sense for monad to depend on maybe (and other monad packages)? I'm thinking of it more like an extension package (eg. ggplot or shiny extension). You would control the function wrappers, and users can opt in at any time. If you create tests that fail if the monad packages change their APIs you would be notified by a revdepcheck before the breaking change was on cran. |
Yeah maybe. I've been mulling it over, and I keep going back and forth. I'm not a fan of the testing burden that comes with that, but then again it's only I think the ideal situation would be that the implementing package exports the methods with an That said, the exporting should be made to be really simple for the implementing packages. And I don't think that's the case with S7 at the moment. I made a branch with what would be required for {maybe}, and I still had some weird behaviour with it. I also couldn't work out a way around the That's why I'm now considering that perhaps {monad} should just provide good old S3 generics. Then all you would need in {maybe} would be #' @exportS3Method monad::fmap
fmap.maybe <- function(m, f, ...) {
maybe_map(m, f, ...)
}
#' @exportS3Method monad::bind
bind.maybe <- function(m, f, ...) {
and_then(m, f, ...)
}
#' @exportS3Method monad::join
join.maybe <- function(m) {
maybe_flatten(m)
} |
Using S3 in monad might limit its future possibilities though. And I don't think I've considered those carefully enough at this stage. So the best approach right now is likely, as you suggested, to have the method registrations in monad. |
The maybe type probably should be an S7 object since the data contained in it is meant to be opaque. Is S7 not recommended as a CRAN dependency yet? According to the CRAN page for S7 there are no reverse dependencies. https://cloud.r-project.org/web/packages/S7/index.html |
I think it's still quite early days for S7, as the first CRAN release was only a few weeks ago. I'm sure they would appreciate feedback from early adopters though. |
I've gone ahead and added the I'm quite happy with how this has turned out, and at the moment I don't think there's a need to suggest any changes to {maybe}. Perhaps at some point in the future (once {monad} is on CRAN and the scope is well established) it might be appropriate for you to consider deprecating Happy to close this issue if you don't see any further need to keep it open. |
Yeah that makes sense to me. Interested to see where your package goes in the future! |
I'm working on an experimental package monad to provide generics and associated operators for monads. When looking for existing implementations, I came across your very clean implementation of the Maybe monad here.
Would you be interested in coordinating to use generic versions of
fmap()
,bind()
andjoin()
to get infix pipe operators? Since you already have the method implementations in {maybe} (with the same names even), it should be quite straightforward:The text was updated successfully, but these errors were encountered: