[Haskell-cafe] foldr (.) id

dag.odenhall at gmail.com dag.odenhall at gmail.com
Sat Oct 27 01:33:22 CEST 2012


Or using the lens package:

>>> :m Data.Foldable Control.Lens Data.Monoid.Lens
>>> ala _endo foldMap [(+1), (*2)] 8
17

On Sat, Oct 27, 2012 at 1:01 AM, Tony Morris <tonymorris at gmail.com> wrote:

> **
> It's the Endo monoid.
>
> λ> :t ala Endo foldMap -- see newtype package
> ala Endo foldMap :: Foldable t => t (a -> a) -> a -> a
> λ> ala Endo foldMap [(+1), (*2)] 8
> 17
> λ> :i ala
> ala ::
>   (Newtype n o, Newtype n' o') =>
>   (o -> n) -> ((o -> n) -> b -> n') -> b -> o'
>       -- Defined in Control.Newtype
>
>
>
> On 27/10/12 04:41, Greg Fitzgerald wrote:
>
> Hi Haskellers,
>
> I've recently found myself using the expression: "foldr (.) id" to compose
> a list (or Foldable) of functions.  It's especially useful when I need to
> map a function over the list before composing.  Does this function, or the
> more general "foldr fmap id", defined in a library anywhere?  I googled and
> hoogled, but no luck so far.
>
> Thanks,
> Greg
>
>
>
> _______________________________________________
> Haskell-Cafe mailing listHaskell-Cafe at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> --
> Tony Morrishttp://tmorris.net/
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121027/55bc7d6a/attachment.htm>


More information about the Haskell-Cafe mailing list