Proposal: Make Semigroup as a superclass of Monoid

Henning Thielemann lemming at henning-thielemann.de
Sun Mar 29 12:29:22 UTC 2015


On Sun, 29 Mar 2015, Jeremy wrote:

> 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid
> instances, and anything else which forms a Semigroup, will have a Semigroup
> instance. GHC will issue a warning when it encounters an instance of Monoid
> which is not an instance of Semigroup.

Good news!

Btw. in my package 'non-empty' I use a more general type:

NonEmpty f a = Cons a (f a)

It allows you to create non-empty Sequences etc. and lists with at least 
two elements (NonEmpty (NonEmpty []) a).

However, inclusion of this type in base or replacing the NonEmpty type 
from "semigroups" is not necessary, since the more general type can stay 
in the "non-empty" package and get an Semigroup instance there.


> The rationale for this change is:
>
> 3. NonEmpty is often redefined by beginners (or those who don't think it's
> worth having an extra dependency for).

And it is often implemented in unnecessarily complicated ways using GADTs 
or phantom types.


More information about the Libraries mailing list