Generalize filterM to Applicative

Yitzchak Gale gale at sefer.org
Sun Dec 28 18:14:20 UTC 2014


David Feuer wrote:
> filterM          :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
> We could change this to
> filterM :: (Applicative f) => (a -> f Bool) -> [a] -> f [a]

Following the usual conventions, that should be filterA.

And I'm not sure where it should go. We could also
generalize the list parameter to a Foldable and put
it in Data.Foldable, but I don't think that would be
very useful, since in the end it anyway returns a list.

We could add a new "Filterable" class, but that's also
probably not too useful for anything not list-like. For
example, Data.Tree has two useful filters, filterGraft
and filterPrune.

So maybe it should go in Control.Applicative? Not very
satisfying. Any ideas?

As for the fate of the name filterM:

Personally, I would want filterM to remain a convenient
type-specialized version for monads. But recent madness
would turn it into yet another unsightly overly polymorphic
namespace wasting synonym for filterA.

Thanks,
Yitz


More information about the Libraries mailing list