- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从 Monoid Morphisms, Products, and Coproducts 读到了幺半群同态并且无法100%理解。
作者说(强调原创):
The
length
function maps fromString
toInt
while preserving the monoid structure. Such a function, that maps from one monoid to another in such a preserving way, is called a monoid homomorphism. In general, for monoidsM
andN
, a homomorphismf: M => N
, and all valuesx:M
,y:M
, the following equations hold:f(x |+| y) == (f(x) |+| f(y))
f(mzero[M]) == mzero[N]
他的意思是这样吗,因为数据类型 String
和 Int
是幺半群,并且函数 length
映射 String => Int
保留幺半群结构(Int
是一个幺半群),这就是所谓的幺半群同态,对吗?
最佳答案
Does he mean, the datatype String and Int are monoid.
不,都没有String
也不Int
是幺半群。幺半群是一个三元组(S, ⊕, e),其中⊕是二元运算符⊕:S×S → S,这样对于所有元素 a, b, c∈S 则有 (a⊕b)⊕c=a⊕(b⊕c),且 e∈S 是“单位元”使得a⊕e=e⊕a=a。 String
和Int
是类型,所以基本上是值的集合,但不是三元组。
文章说:
Let's take the
String
concatenation andInt
addition as example monoids that have a relationship.
因此,作者显然还提到了二元运算符(在 (++)
的情况下为 String
,在 (+)
的情况下为 Int
)。身份(在 String
的情况下为空字符串,在 0
的情况下 Int
)保持隐式;在非正式英语对话中,将身份留给读者作为练习是很常见的。
现在假设我们有两个幺半群结构(M, ⊕, em)和(N, ⊗, en),函数 f : M → N (如 length
)被称为 monoid homomorphism [wiki]鉴于它成立 f(m1⊕m2)=f(m1)⊗f(m2 ) 对于所有元素 m1, m2∈M 并且该映射还保留单位元素:< em>f(em)=en.
例如length :: String -> Int
是幺半群同态,因为我们可以考虑幺半群 ( String
, (++)
, ""
) 和 ( Int
, (+)
, 0
)
。认为:
length (s1 ++ s2) == length s1 + length s2
(对于所有 String
s s1
和 s2
);和length "" == 0
.关于scala - 到底什么是幺半群同态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55993254/
我是一名优秀的程序员,十分优秀!