monad-loops icon indicating copy to clipboard operation
monad-loops copied to clipboard

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

Open is7s opened this issue 13 years ago • 2 comments

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 ().

is7s avatar May 31 '12 08:05 is7s

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.

mokus0 avatar Jun 04 '12 15:06 mokus0

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.

is7s avatar Jun 04 '12 20:06 is7s