[Haskell-cafe] Alternative versus Monoid

Anthony Cowley acowley at gmail.com
Thu Dec 15 16:51:11 CET 2011


On Dec 15, 2011, at 10:19 AM, Brent Yorgey wrote:

> 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})

We already have,

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

So the overlap of apparent Alternative and Monoid functionality remains. This just represents an opportunity for the caller to select the monoid they want.

Anthony


More information about the Haskell-Cafe mailing list