小编ste*_*tew的帖子

Monoid[String] 真的是 scala 中的 Monoid

我目前正在学习 scala 中的范畴论,结合律说

(x + y) + z = x + (y + z)

当使用两个以上的值时就很好了

("Foo" + "Bar") + "Test" == "Foo" + ("Bar" + "Test") // true
Run Code Online (Sandbox Code Playgroud)

在这种情况下,顺序并不重要。但是如果只有两个值怎么办?对于数字,它仍然有效(可交换),但是当对字符串执行相同的操作时,它会失败。

3+1==1+3 // True
("Foo" + "Bar") == ("Bar" + "Foo") // Not commuative
Run Code Online (Sandbox Code Playgroud)

那么,说结合性需要交换性来满足幺半群定律是否合法?那么字符串 Monoid 是否有效?

scala category-theory monoids

1
推荐指数
1
解决办法
390
查看次数

标签 统计

category-theory ×1

monoids ×1

scala ×1