Proposal: Make Semigroup as a superclass of Monoid

wren romano winterkoninkje at gmail.com
Tue Apr 7 03:15:31 UTC 2015


I'm +1 for getting the Prelude to eventually say:

    class Semigroup a where
        mappend :: a -> a -> a
        mconcat :: [a] -> a

    (<>) = mappend
    infixr 6 <>

    class Semigroup a => Monoid a where
        mempty :: a

    instance Semigroup a => Monoid (Maybe a) where...


The long path seems the most sensible way to get here with a minimum
of breakage. Tis a shame it'll take so long to complete.




(ObBikeshed: Honestly, I'd rather see:

    class Semigroup a where
        (<>) :: a -> a -> a
        concat :: [a] -> a -- or: concat :: Foldable f => f a -> a

...getting rid of the mwhatever naming scheme and avoiding taking two
names for one function. The name "concat" is pretty ubiquitously used
for monomorphic variants of the [a]->a type. The notable exception
being Foldable.concat, which relies specifically on using the [a]
semigroup for no especially interesting reason I can discern. But I'm
pretty sure that ship has sailed unless we give up hope of providing a
breakage-free upgrade path.)

-- 
Live well,
~wren


More information about the Libraries mailing list