Proposal: Add Alternative adapter to Data.Monoid
John Lato
jwlato at gmail.com
Thu Oct 30 16:52:41 UTC 2014
+1, I think I've defined one-off, specialized versions of this a dozen
times.
On Thu, Oct 30, 2014 at 9:46 AM, David Feuer <david.feuer at gmail.com> wrote:
> I found myself needing this type in my current overhaul of Data.Foldable,
> but it seems to be generally useful:
>
> newtype Alt f a = Alt { getAlt :: f a } deriving
> (Eq,Ord,Show,Read,Typeable,Data,Generic,Num,Real,
> Floating, Fractional, RealFrac, RealFloat, Integral, Enum,
> Bounded,Ix,Functor,Foldable,Traversable,Applicative,
> Alternative,Monad,MonadPlus,MonadFix, IsString, IsList)
> -- The laundry list of derived instances is as recommended by Edward
> Kmett, who would probably want more added if someone can think of more.
> Some of them would, of course, need to be derived in other modules. The key
> instance is this:
>
> instance Alternative t => Monoid (Alt t a) where
> mempty = Alt empty
> (Alt m) `mappend` (Alt n) = Alt (m <|> n)
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141030/b631d6f3/attachment.html>
More information about the Libraries
mailing list