Proposal: Add a wrapped applicative type to Data.Monoid
Andrew Martin
andrew.thaddeus at gmail.com
Tue Mar 27 14:28:02 UTC 2018
+1 from me. I've written this type at least a dozen times in various
projects.
On Tue, Mar 27, 2018 at 10:22 AM, Daniel Cartwright <chessai1996 at gmail.com>
wrote:
> I see this as being generally (as in, to the users of Haskell as a whole)
> useful:
>
> newtype Ap f a = Ap { getAp :: f a }
> deriving (Applicative, Eq, Foldable, Functor, Generic, Generic1
> ,Monad, Ord, Read, Show, Traversable)
>
> Some hand-written instances:
> instance (Applicative f, Semigroup a) => Semigroup (Ap f a) where
> (Ap x) <> (Ap y) = Ap $ liftA2 (<>) x y
>
> instance (Applicative f, Monoid a) => Monoid (Ap f a) where
> mempty = Ap $ pure mempty
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
--
-Andrew Thaddeus Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20180327/36e42c45/attachment.html>
More information about the Libraries
mailing list