
On 2015-08-03, Mario Blažević wrote:
Date: Mon, 3 Aug 2015 10:22:56 From: Mario Blažević
To: libraries@haskell.org Subject: Re: Proposal: newtype for applicatives of monoids On 07/26/2015 11:34 PM, David Feuer wrote:
Sorry for the terrible title, but I think we should add something like the following to Data.Monoid (I already mentioned this in the discussion of a Monoid instance for ZipList).
newtype Appl f m = Appl (f m)
instance (Applicative f, Monoid m) => Monoid (Appl f m) where mempty = Appl $ pure mempty mplus (Appl x) (Appl y) = Appl $ liftA2 mplus x y
The method is called mappend, not mplus. Otherwise +1.
It may be possible to use coercions to improve mplus; I haven't tried it.
This type is the same as WrappedApplicative from semigroupoids, do it might be best just to give it that name.
+1, with mappend. (I just tripped over the Monad instance of the same thing. It's very nice to be able to use (<>) on something like Monad m => Control.Monad.Trans.Exception m () .) Cheers, David -- David Casperson, PhD, R.P., | David.Casperson@unbc.ca Associate Professor and Chair, | (250) 960-6672 Fax 960-5544 Computer Science | 3333 University Way University of Northern British Columbia | Prince George, BC V2N 4Z9 | CANADA