The documentation for algebra/2.1.1.2/doc/html shows a colossal number of type classes.
How do I declare that a structure in question must be equipped with a commutative associative operation and a unit/identity element, but without anything else (inverses, distributivity etc)?
I'm thinking of
reduce :: Monoid m => (a -> m) -> [a] -> m
but instances of Data.Monoid are not supposed to be commutative and I want users of my function to see that they need commutativity for the function to work by looking at the type.
Commutative
talks about the action of theMultiplicative
class, notMonoid
. You could use(Commutative m, Unital m)
to get a multiplicative commutative monoid that works with(*)
andone
, or(Abelian m, Monoidal m)
to get a commutative monoid that works with(+)
andzero
. – Headrest