Proposal: add liftA4 and liftA5 to match liftM4 and liftM5

Jacques Carette carette at mcmaster.ca
Fri Nov 7 12:47:10 UTC 2014


On 2014-11-07 5:30 AM, Henning Thielemann wrote:
>
> On Fri, 7 Nov 2014, Andreas Abel wrote:
>
>> I hope the same happens for sequence, mapM and the like!
>>
>>  sequence :: (Applicative m) => [m a] -> m [a]
>>  sequence = foldr (\ x xs -> (:) <$> x <*> xs) (pure [])
>
> Actually, this is an example, where liftA2 shows its advantage:
>
>   sequence = foldr (liftA2 (:)) (pure [])
>
> This looks much clearer to me than decoding the mixture of infix and 
> uninfixed infix operators. It simply says, that 'sequence' is like 'id 
> = foldr (:) []' but with everything lifted to an applicative functor.

I agree.  I have lots of code which looks really clean because I can use 
liftA2 (and even liftA3) in exactly the way above.  Having to eta expand 
everything obscures the real meat of what is going on.

Jacques


More information about the Libraries mailing list