Proposal: add Monoid1 and Semigroup1 classes

David Feuer david.feuer at gmail.com
Fri Sep 30 23:25:21 UTC 2016


I've been playing around with the idea of writing Haskell 2010 type classes
for finite sequences and non-empty sequences, somewhat similar to Michael
Snoyman's Sequence class in mono-traversable. These are naturally based on
Monoid1 and Semigroup1, which I think belong in base.

class Semigroup1 f where
  (<<>>) :: f a -> f a -> f a
class Semigroup1 f => Monoid1 f where
  mempty1 :: f a

Then I can write

class (Monoid1 t, Traversable t) => Sequence t where
  singleton :: a -> t a
  -- and other less-critical methods

class (Semigroup1 t, Traversable1 t) => NESequence where
  singleton1 :: a -> t a
  -- etc.

I can, of course, just write my own, but I don't think I'm the only one
using such.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160930/1b41f485/attachment.html>


More information about the Libraries mailing list