本文介绍了我应该如何思考Scala的产品类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

包scala有许多类,分别命名为Product,Product1,Product2等,直到Product22。



这些类的描述是肯定的精确。例如:

  Product4是一个笛卡尔积,包含4个部分

精确,是的。交际?没那么多。我期望这对于已经理解这里使用的笛卡尔产品意义的人来说是完美的措辞。对于没有的人来说,这听起来有点循环。 哦,是的,当然产品4是4毫米笨拙的产品。



请帮忙我了解正确的功能语言观点。这里使用的笛卡尔积是什么意思?什么是产品类别的投影成员表示的?

具体而言,两组X的笛卡尔乘积(例如X轴上的点)和Y(例如,表示为X×Y的点是所有可能的有序对的集合,其第一分量是X的成员并且其第二分量是Y的成员(例如整个xy平面)

也许可以通过了解从中派生出来的人来获得更好的理解:

直接已知的子类:
Tuple4



或者,知道 extends Product ,知道其他类可以做什么通过扩展 Product 本身来使用它。不过,我不会在这里引用,因为它相当长。



无论如何,如果您有类型A,B,C和D,则Product4 [A,B ,C,D]是一个类,它的实例是A,B,C和D的笛卡尔乘积的所有可能元素。字面意思。 b
$ b

当然,除产品4是一个特质,而不是一个班级。它只是提供了几种有用的方法,用于四类不同集合的笛卡尔积类。


The package "scala" has a number of classes named Product, Product1, Product2, and so on, up to Product22.

The descriptions of these classes are surely precise. For example:

Product4 is a cartesian product of 4 components

Precise, yes. Communicative? Not so much. I expect that this is the perfect wording for someone who already understands the sense of "cartesian product" being used here. For someone who doesn't, it sounds a bit circular. "Oh yes, well of course Product4 is the mumble product of 4 mumble-mumbles."

Please help me understand the correct functional-language viewpoint. What is the sense of "cartesian product" being used here? What do the Product classes' "projection" members indicate?

解决方案

"The set of all possible pairs of elements whose components are members of two sets."

"Specifically, the Cartesian product of two sets X (for example the points on an x-axis) and Y (for example the points on a y-axis), denoted X × Y, is the set of all possible ordered pairs whose first component is a member of X and whose second component is a member of Y (e.g. the whole of the x-y plane)"

Perhaps better understanding can be gained by knowing who derives from it:

Direct Known Subclasses:Tuple4

Or by, knowing it "extends Product", know what other classes can make use of it, by virtue of extending Product itself. I won't quote that here, though, because it's rather long.

Anyway, if you have types A, B, C and D, then Product4[A,B,C,D] is a class whose instances are all possible elements of the cartesian product of A, B, C and D. Literally.

Except, of course, that Product4 is a Trait, not a class. It just provides a few useful methods for classes that are cartesian products of four different sets.

这篇关于我应该如何思考Scala的产品类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:21