我应该如何看待 Scala 的 Product 类? [英] How should I think about Scala's Product classes?

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

问题描述

scala"包有许多类,名为 Product、Product1、Product2,依此类推,直到 Product22.

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

准确,是的.沟通?没那么多.我希望对于已经理解此处使用的笛卡尔积"含义的人来说,这是一个完美的措辞.对于不知道的人来说,这听起来有点循环.哦,是的,当然 Product4 是 4 个 mumble-mumblesmumble 产品."

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."

请帮助我理解正确的函数式语言观点.这里使用的笛卡尔积"是什么意思?Product 类的投影"成员表示什么?

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?

推荐答案

"所有可能的集合成对的元素,其组件是两个集合的成员."

"具体来说,两个集合 X 的笛卡尔积(例如 x 轴上的点)) 和 Y(例如 y 轴上的点),表示为 X × Y,是所有可能的有序对的集合,其第一个组件是 X 的成员,其第二个组件是 Y 的成员(例如整个xy平面)"

也许可以通过了解谁从中获得更好的理解:

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

直接已知子类:Tuple4

或者,通过了解它扩展产品",通过扩展Product 本身,知道其他类可以使用它.不过,我不会在这里引用,因为它很长.

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.

无论如何,如果您有 ABCD 类型,那么 Product4[A,B,C,D] 是一个类,其实例都是 A, B, C<的笛卡尔积的所有可能元素/code> 和 D.字面意思.

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.

当然,除了 Product4 是一个 Trait,而不是一个类.它只是为四个不同集合的笛卡尔积的类提供了一些有用的方法.

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 的 Product 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆