Foldable.Mapped

Oliver Charles ollie at ocharles.org.uk
Mon Jan 4 00:43:07 UTC 2016


Could you provide some examples where you have found it useful?

On Sun, Jan 3, 2016 at 9:11 PM Henning Thielemann <
lemming at henning-thielemann.de> wrote:

>
> I found the following data type useful when working with the Foldable
> class:
>
>
> {- |
> It holds:
>
> > foldMap f . Mapped g = foldMap f . fmap g
>
> but use of 'Mapped' avoids 'Functor' constraint.
> -}
> data Mapped f a b = Mapped (a -> b) (f a)
>
>
> instance (Foldable f) => Foldable (Mapped f a) where
>     foldMap g (Mapped f xs) = Fold.foldMap (g . f) xs
>     foldr g x (Mapped f xs) = Fold.foldr (g . f) x xs
>     foldl g x (Mapped f xs) = Fold.foldl (\acc -> g acc . f) x xs
>
>
> Should it be added to Data.Foldable?
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160104/386880cd/attachment.html>


More information about the Libraries mailing list