<div dir="ltr">-1 This has the same problem as making Functor a superclass of Monad, all current instances will break.<div><br></div><div>> <span style="font-family:arial,sans-serif;font-size:13px">This is somewhat in the spirit of the AMP proposal: further improving the</span></div>
<span style="font-family:arial,sans-serif;font-size:13px">> correctness of our algebraic abstractions.</span><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div style><span style="font-family:arial,sans-serif;font-size:13px">I don't think building a tower of all possible algebraic abstractions is a useful goal. We should add those that are actually useful (which functors, applicative functions, monads, and monoids have proved to be). I don't want to see us break all current code every time someone decides that we should add another layer (pointed, say) between e.g. functor and monad.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 11:46 AM, John Wiegley <span dir="ltr"><<a href="mailto:johnw@fpcomplete.com" target="_blank">johnw@fpcomplete.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">1. I propose that we add the following package to base:<br>
<br>
<a href="http://hackage.haskell.org/packages/archive/semigroups/0.9.2/doc/html/Data-Semigroup.html" target="_blank">http://hackage.haskell.org/packages/archive/semigroups/0.9.2/doc/html/Data-Semigroup.html</a><br>
<br>
This is somewhat in the spirit of the AMP proposal: further improving the<br>
correctness of our algebraic abstractions.<br>
<br>
2. That we make Semigroup a superclass of Monoid, so that (minimally):<br>
<br>
class Semigroup a where<br>
(<>) :: a -> a -> a<br>
<br>
class Semigroup a => Monoid a where<br>
mempty :: a<br>
mconcat :: [a] -> a<br>
mconcat = foldr (<>) mempty<br>
<br>
mappend :: Semigroup a => a -> a -> a<br>
mappend = (<>)<br>
<br>
3. (Optional, recommended) There are other useful functions that can be added<br>
to Semigroup, such as sconcat and times1p, but I will let Edward speak to<br>
whether those should be proposed at this time.<br>
<br>
4. (Optional, recommended) That we fix the Monoid instance for Maybe to be:<br>
<br>
instance Semigroup a => Semigroup (Maybe a) where<br>
Just x <> Just y = Just (x <> y)<br>
_ <> _ = Nothing<br>
<br>
instance Semigroup a => Monoid (Maybe a) where<br>
mempty = Nothing<br>
<br>
<br>
For some clarification on what semigroups are and why we'd want to change<br>
Monoid, I excerpt here a selection from Brent Yorgey's "Monoids and<br>
Variations" paper:<br>
<br>
Semigroups<br>
<br>
A semigroup is like a monoid without the requirement of an identity element:<br>
it consists simply of a set with an associative binary operation....<br>
<br>
Of course, any monoid is automatically a semigroup (by forgetting about its<br>
identity element). In the other direction, to turn a semigroup into a<br>
monoid, simply add a new distinguished element to serve as the identity, and<br>
extend the definition of the binary operation appropriately. This creates<br>
an identity element by definition, and it is not hard to see that it<br>
preserves associativity....<br>
<br>
Adding a new distinguished element to a type is typically accomplished by<br>
wrapping it in Maybe. One might therefore expect to turn an instance of<br>
Semigroup into an instance of Monoid by wrapping it in Maybe. Sadly,<br>
Data.Monoid does not define semigroups, and has a Monoid instance for Maybe<br>
which requires a Monoid constraint on its argument type...<br>
<br>
This is somewhat odd: in essence, it ignores the identity element of [the<br>
type] and replaces it with a different one.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
John Wiegley<br>
FP Complete Haskell tools, training and consulting<br>
<a href="http://fpcomplete.com" target="_blank">http://fpcomplete.com</a> johnw on #haskell/<a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a><br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</font></span></blockquote></div><br></div>