Scala 的列表是否在串联运算符下形成幺半群?
Does Scala's list form a monoid under the concatenation operator?
首先,抱歉,我的母语不是英语。不过我会努力做到最好的。
我实际上是在研究一些理论概念作为一种爱好,以加深我对函数式编程的理解,并有一些问题来检查我是否正确理解了什么是幺半群。
首先我查到的幺半群的定义是,幺半群是在结合二元运算下闭集,并且有一个恒等元的集合。我想这是正确的?
因此,使用以下定义,我假设 Scala 的列表在 :::
运算符下形成一个幺半群,因为 List
是一个集合,:::
是关联的 (xs ::: (ys ::: zs) = (xs ::: ys) ::: zs)
和 List
有一个基本元素 (Nil
)。我说得对吗?
关于幺半群,关于 ::
List
运算符有什么要说的吗?我想不是因为它没有将两个列表作为参数,而是一个元素和一个 List
。我还是对的吗?
First of all, the definition of a monoid that I found is that a monoid is a set that is closed under an associative binary operation and has an identity element. I guess it's correct?
据我所知,这是正确的。 (免责声明:我也在学习).
So, using the following definition, I suppose that Scala's lists form a monoid under the ::: operator, as List is a set, ::: is associative (xs ::: (ys ::: zs) = (xs ::: ys) ::: zs) and List has a base element (Nil). Am I right?
也正确。
例如这里是 Monoid[List[A]]
in Cats - and here is an specification of the Monoid[List[A]]
in Scalaz.
的定义
两者都是 libraries/frameworks,用于 scala 中的函数式编程,如您所见,它们都使用 :::
和 Nil
.[= 为 List 定义了 Monoid。 18=]
Regarding monoids, is there something to say about the :: List operator? I suppose not as it's not taking two lists as parameters, but an element and a List. Am I still right?
据我所知,你还是对的。
首先,抱歉,我的母语不是英语。不过我会努力做到最好的。
我实际上是在研究一些理论概念作为一种爱好,以加深我对函数式编程的理解,并有一些问题来检查我是否正确理解了什么是幺半群。
首先我查到的幺半群的定义是,幺半群是在结合二元运算下闭集,并且有一个恒等元的集合。我想这是正确的?
因此,使用以下定义,我假设 Scala 的列表在 :::
运算符下形成一个幺半群,因为 List
是一个集合,:::
是关联的 (xs ::: (ys ::: zs) = (xs ::: ys) ::: zs)
和 List
有一个基本元素 (Nil
)。我说得对吗?
关于幺半群,关于 ::
List
运算符有什么要说的吗?我想不是因为它没有将两个列表作为参数,而是一个元素和一个 List
。我还是对的吗?
First of all, the definition of a monoid that I found is that a monoid is a set that is closed under an associative binary operation and has an identity element. I guess it's correct?
据我所知,这是正确的。 (免责声明:我也在学习).
So, using the following definition, I suppose that Scala's lists form a monoid under the ::: operator, as List is a set, ::: is associative (xs ::: (ys ::: zs) = (xs ::: ys) ::: zs) and List has a base element (Nil). Am I right?
也正确。
例如这里是 Monoid[List[A]]
in Cats - and here is an specification of the Monoid[List[A]]
in Scalaz.
的定义
两者都是 libraries/frameworks,用于 scala 中的函数式编程,如您所见,它们都使用 :::
和 Nil
.[= 为 List 定义了 Monoid。 18=]
Regarding monoids, is there something to say about the :: List operator? I suppose not as it's not taking two lists as parameters, but an element and a List. Am I still right?
据我所知,你还是对的。