为什么 Haskell 中仿函数的幺半群没有类型 class?

Why is there no type class for monoids on functors in Haskell?

我承认这个问题有点不明确,但我想知道为什么我从来没有在 Haskell 中偶然发现仿函数上的幺半群类型 class。我只是错过了它吗,这种缺席是否有充分的理由,还是完全是由于历史原因?恕我直言,下面的继承图表没有右上角看起来有点奇怪:

  Functor
     |
     V
Applicative ––> Alternative
     |               |
     V               V
   Monad    ––>  MonadPlus

这里要考虑的一个关键因素是,"What does the arrow from Functor really mean?" 如果没有 公理 FunctorFunctorPlus 统一起来,那么您可能也只需定义 instance Monoid (F t) where ... 并完成它。那么您在寻找什么公理 - 只是 fmap f fempty = fempty 还是 fmap f x <|> fmap f y == fmap f (x <|> y)...?

另一个关键因素是缺乏有趣的结构,这些结构是仿函数而不是应用函数。可能有一个与泛型编程(deriving 关键字元编程)有关的争论,其中一切都是产品的总和,因此我们可以为任何类型的 * -> * 推导出 Applicative,但我不知道详情。 FunctorPlus 可能具有的唯一值是 "doing the same thing that Alternative does for Functors which are not Applicative,",因此如果该集合真的很小,那么显然不会增加太多价值。