问题描述
代数/2.1.1.2/doc/html 显示了种类繁多的类型类.
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)?
我在想
reduce :: Monoid m => (a -> m) -> [a] -> m
但是Data.Monoid的实例不应该是可交换的,我希望函数的用户可以通过查看类型来了解他们需要函数的交换性.
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.
推荐答案
(Abelian m, Monoidal m)
Monoidal
似乎比您想要的要多得多,但这完全基于Natural
是Semiring
.
It might seem that Monoidal
is much more than you want, but it is all based on Natural
being a Semiring
.
这篇关于来自Hackage的'代数'包的可交换monoid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!