Proposal: Add Alternative adapter to Data.Monoid

David Feuer david.feuer at gmail.com
Thu Oct 30 16:46:32 UTC 2014


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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141030/de923c2a/attachment.html>


More information about the Libraries mailing list