distums / distums.github.io

my personal blog
https://distums.github.io/
0 stars 0 forks source link

monoid #21

Open distums opened 6 years ago

distums commented 6 years ago

定义

  1. fantasy land

  2. 设一个非空集合G,G上定义的二元运算*满足:

    • 封闭性:对于任意a, b ∈ G,有 a * b ∈ G;
    • 结合性:对于任意a, b, c ∈ G,有 (a b) c = a (b c);
    • 单位元:存在单位元 e ∈ G,使得对任意 a ∈ G,有 a e = a = e a; 则(G, *)是一个monoid
distums commented 6 years ago

为什么有用

monoid的结合性抽象了构建的细节,提供了无限组合元素的能力,而不用关心组合的具体细节。并且组合而得的元素和可以和普通元素一样使用,实际上我们没法区分元素是组合而来还是普通元素。

如果没有结合性,依赖于结合的顺序,我们会得到不一样的结果。

distums commented 6 years ago

纯函数

数学上函数是满足结合律的:f g h = f (g h)。而纯函数即对应数学上的函数,非纯函数会破坏结合律。