Re: [Haskell-cafe] Re: (liftM join .) . mapM
Hi Maciej On 29 Dec 2009, at 20:52, Maciej Piechotka wrote: On Tue, 2009-12-29 at 18:20 +, 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: (liftM join .) . mapM
2009/12/29 Dominic Steinitz : > And oo = (.).(.) and ooo = (.).(.).(.) > > There was a suggestion a few years back to standardise these as I recall > something like: > > $0 = $ > $1 = . > $2 = (.).(.) > > and so on but nothing came of it. Hi Dominic Hmm, name-wise I would have to be dishonourable and vote for myself on this particular one. But, I rather suspect that Haskell-prime-prime (or whatever it gets called in a few years time) will bite the bullet and go for Unicode symbols, otherwise we'll be doomed to programs that look somewhat 'expletive-deleted'. Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: (liftM join .) . mapM
Stephen Tetley gmail.com> writes: > -- | Compose an arity 1 function with an arity 2 function. > -- B1 - blackbird > oo :: (c -> d) -> (a -> b -> c) -> a -> b -> d > oo f g = (f .) . g > > Extending the arity works quite nicely too: > > -- | Compose an arity 1 function with an arity 3 function. > -- B2 - bunting > ooo :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e > ooo f g = ((f .) .) . g And oo = (.).(.) and ooo = (.).(.).(.) There was a suggestion a few years back to standardise these as I recall something like: $0 = $ $1 = . $2 = (.).(.) and so on but nothing came of it. Dominic. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: (liftM join .) . mapM
On Tue, 2009-12-29 at 18:20 +, Conor McBride wrote: > Hi Tony > > On 29 Dec 2009, at 12:10, Tony Morris wrote: > > > Can (liftM join .) . mapM be improved? > > (Monad m) => (a -> m [b]) -> [a] -> m [b] > > You can > >(a) generalize m from Monad to Applicative >(b) generalize [b] to any Monoid >(c) generalize [a] to f a for any Foldable f > > and write > >ala AppLift foldMap > > if you happen to have some of my usual kit. See below. > > Cheers > > Conor What is benefit of it over: concatMapA f = foldr (liftA2 mappend . f) (pure mempty) Regards ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe