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

Add zipWithM' :: (MonadPlus m, Functor m) => (a -> b -> m c) -> [a] -> [b] -> m [c] #2

Open
is7s opened this issue May 31, 2012 · 2 comments

Comments

@is7s
Copy link

is7s commented May 31, 2012

Hi,
I find this function handy sometimes. A zipWithM for lists of equal length.

zipWithM' :: (MonadPlus m, Functor m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM' _ [] [] = return []
zipWithM' f (x:xs) (y:ys) = (:) `fmap` f x y `ap` zipWithM' xs ys
zipWithM' _ _ _ = mzero

And of course it's counterpart zipWithM'_ :: MonadPlus m => (a -> b -> m c) -> [a] -> [b] -> m ().

@mokus0
Copy link
Owner

mokus0 commented Jun 4, 2012

This seems very special-purpose. I'm not sure it makes sense to include here, at least not without a more descriptive name. People who don't realize there's already a zipWithM in Control.Monad would likely assume a function with this name to be the same, and the use of the "prime" doesn't really match that of other functions in this package or the more widely known convention (that it indicates a stricter version of the same function).

I'm not totally against it, but I think I need a fairly compelling argument or a more descriptive name before I'll be convinced it fits.

@is7s
Copy link
Author

is7s commented Jun 4, 2012

Well I don't see how this is "very special-purpose" I've found use cases for it in real code I've implemented while I never actually needed to use zipWithM from Control.Monad in real code.
I actually suggested the name zipWithM' since it goes well with the naming conventions of the packages itself mentioned here. "Functions with names ending in ' collect their results into MonadPlus containers."
I don't care at all about the name though. If you find a more appropriate name please use it.

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