Generalize filterM to Applicative

M Farkas-Dyck strake888 at gmail.com
Wed Mar 25 20:06:47 UTC 2015


On 05/01/2015 at 11:53:11 -0500, Mario Blažević wrote:
> On 14-12-30 12:34 PM, David Feuer wrote:
> >I realized just now that we can actually make the type a little bit
> >more general still, interpreting `filterM` for lists as being an
> >applicative filter *producing* lists:
> >
> >filterM :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f [a]
> 
> 	I'm +1 on the more limited generalization proposal, but not on this one.
> I've been feeling for a while that we need a subclass of Traversable to
> generalize functions like filter, mapMaybe, and partition (potentially span,
> splitAt and others as well). If you call this missing class Filterable, the
> properly-generalized signature would be
> 
> > filterM :: (Applicative f, Filterable t) =>
> > (a -> f Bool) -> t a -> f (t a)

https://hackage.haskell.org/package/witherable

Interesting name choice...


More information about the Libraries mailing list