Generalize filterM to Applicative

Mario Blažević mblazevic at stilo.com
Mon Jan 5 16:53:11 UTC 2015


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)



>
> On Mon, Dec 29, 2014 at 3:17 PM, Edward Kmett <ekmett at gmail.com> wrote:
>> I think this is the interpretation I think we're probably best left with.
>>
>> I agree that names matter and that anachronistic labels confuse, but I think
>> it is the lesser of evils to widen the definition of the 'M' suffix than it
>> is to double up on almost all the names taken in the environment and force
>> the entire community to go through a positively gigantic deprecation cycle.
>>
>> -Edward
>>
>> On Mon, Dec 29, 2014 at 1:31 PM, Andreas Abel <andreas.abel at ifi.lmu.de>
>> wrote:
>>>
>>> Or you can widen the interpretation of suffix ...M as "effectful", which
>>> could be a monadic or applicative effect.
>>>
>>> On 29.12.2014 16:50, Kim-Ee Yeoh wrote:
>>>>
>>>>
>>>> On Mon, Dec 29, 2014 at 7:58 PM, Edward Kmett <ekmett at gmail.com
>>>> <mailto:ekmett at gmail.com>> wrote:
>>>>
>>>>      Is it "madness" to want to avoid namespace proliferation and
>>>>      maximize the usefulness of an existing combinator now that the
>>>>      constraints that forged it have changed to allow it to be slightly
>>>>      more permissive?
>>>>
>>>>
>>>> Madness is such strong language for this august list.
>>>>
>>>> May I speak on behalf of haskell newcomers for a time?
>>>>
>>>> Haskell places such an emphasis on uniformity and regularity. Functions
>>>> with names that end with M once meant they were monadic variants of
>>>> those that don't. That's no longer uniformly the case, because of the
>>>> FAM restructuring.
>>>>
>>>> The names of functions matter.
>>>>
>>>> Anachronistic labels confuse.
>>>>
>>>> Leaving filterM with a type signature of Applicative cannot be the
>>>> long-term solution.
>>>>
>>>> -- Kim-Ee
>>>>
>>>>
>>>> _______________________________________________
>>>> Libraries mailing list
>>>> Libraries at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/libraries
>>>>
>>>
>>>
>>> --
>>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>>
>>> Department of Computer Science and Engineering
>>> Chalmers and Gothenburg University, Sweden
>>>
>>> andreas.abel at gu.se
>>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>


-- 
Mario Blazevic
mblazevic at stilo.com
Stilo International

This message, including any attachments, is for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure, copying, or
distribution is strictly prohibited. If you are not the intended
recipient(s) please contact the sender by reply email and destroy
all copies of the original message and any attachments.


More information about the Libraries mailing list