Fwd: Applicative-based definitions in Data.Foldable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Applicative-based definitions in Data.Foldable

Isaac Elliott
With the introduction of the 'Ap' monoid in base-4.13, it seems like Applicative based definitions for common folds would be appropriate in base.

For example:
allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool
allA f = fmap getAll . getAp . foldMap (Ap . fmap All . f)
 
all :: Foldable t => (a -> Bool) -> t a -> Bool
all f = runIdentity . allA (Identity . f)

I've personally written the Applicative version in everyday code. Thoughts?

Isaac

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Applicative-based definitions in Data.Foldable

David Feuer
Can you give a few examples of where you'd want that? I can't think of a good application off the top of my head.

On Thu, Dec 20, 2018 at 8:22 PM Isaac Elliott <[hidden email]> wrote:
With the introduction of the 'Ap' monoid in base-4.13, it seems like Applicative based definitions for common folds would be appropriate in base.

For example:
allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool
allA f = fmap getAll . getAp . foldMap (Ap . fmap All . f)
 
all :: Foldable t => (a -> Bool) -> t a -> Bool
all f = runIdentity . allA (Identity . f)

I've personally written the Applicative version in everyday code. Thoughts?

Isaac
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries