[Haskell-cafe] Alternative versus Monoid

Brent Yorgey byorgey at seas.upenn.edu
Thu Dec 15 16:19:47 CET 2011


On Thu, Dec 15, 2011 at 06:49:13PM +1000, Gregory Crosswhite wrote:
> 
> So at the end of the day... what is the point of even making Maybe and [] instances of Alternative?

The Alternative and Monoid instances for [] are equivalent.  However,
the Alternative and Monoid instances for Maybe are not. To wit:

  > (Just (Sum  4)) <|> (Just (Sum 3))
  Just (Sum {getSum = 4})

  > (Just (Sum 4)) `mappend` (Just (Sum 3))
  Just (Sum {getSum = 7})

-Brent



More information about the Haskell-Cafe mailing list