[Haskell-cafe] Re: (liftM join .) . mapM
Conor McBride
conor at strictlypositive.org
Tue Dec 29 18:00:36 EST 2009
Hi Maciej
On 29 Dec 2009, at 20:52, Maciej Piechotka wrote:
> On Tue, 2009-12-29 at 18:20 +0000, Conor McBride wrote:
>>
>> ala AppLift foldMap
>
> What is benefit of it over:
> concatMapA f = foldr (liftA2 mappend . f) (pure mempty)
Given that applicative functors take monoids to monoids, it's
nice to exploit that property by name, rather than reconstructing
it by engineered coincidence. I reuse the "library" pattern once
(AppLift) that you reinvent in two places (liftA2 mappend)
(pure mempty).
(Ironically, foldr is defined in terms of foldMap by code that
amounts to, modulo a flip,
ala Endo foldMap
appealing to the monoid of endomorphisms.)
The result is an operation which
(a) points out the essential mechanism, foldMap;
(b) points out the structures on which it works, lifted monoids;
(c) is short enough not to bother naming.
More structure, less code,
Conor
More information about the Haskell-Cafe
mailing list