类型的基数
它是什么意思,以及以下类型的基数是什么,例如:
unit->int
bool->(int->bool)
What does it mean, and also what is the cardinality of the next types for example:
unit->int
bool->(int->bool)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类型的基数是该类型的可能合法值的数量。
对于函数类型,我们通常希望将每个输入返回相同值的两个函数视为“相同的函数”,至少出于基数目的(这称为“外延相等”)。
我假设这是一个家庭作业问题,并且我进一步假设不包含不终止或产生未定义值的函数(因为实际上,它们不会包含在典型的数学处理中) 。
原则上,表达可以具有有限数量的可能值的类型的基数相当容易,因为您可以只给出一个数字作为基数。然而,对于无限基数,从技术上讲,不同类型的无穷大之间存在区别。例如,不可数无穷大“大于”可数无穷大。 (说实话,我不确定你是否应该知道这一点,或者你是否应该给出“无限”的答案 - 检查你的课程笔记。)因此,最好指定哪个无穷大您正在谈论,例如通过引用“更简单”类型的基数。
因此
unit->int
的基数与int
的基数相同(对于您可能选择而不是的任何其他目标类型也是如此) int
),因为unit->X
类型的值必须是一个“忽略其输入”并返回X
类型常量值的常量函数>。我希望这个不完整的答案足以让您开始。
The cardinality of a type is the number of possible legal values that can be of that type.
With function types, we usually want to consider two functions that return the same value for every input to be "the same function", for cardinality purposes at least (this is known as "extensional equality").
I am assuming that this is a homework problem, and I am further going to assume that functions which don't terminate or yield undefined values are not to be included (as, indeed, they wouldn't be included in a typical mathematical treatment).
Expressing the cardinality of types which can have a finite number of possible values, is fairly easy in principle, because you can just give a number as the cardinality. However, with infinite cardinalities, technically there is a distinction between different kinds of infinities. For example, an uncountable infinity is "larger than" a countable infinity. (To be honest, I am not sure whether you are expected to know this, or whether you are just supposed to give an answer of "infinite" - check your course notes.) For this reason, it's a good idea to specify which infinity you are talking about, e.g. by referring to the cardinality of a "simpler" type.
So the cardinality of
unit->int
is the same as the cardinality ofint
(and the same goes for any other destination type which you might choose instead ofint
), because a value of typeunit->X
must necessarily be a constant function which "ignores its input" and returns a constant value of typeX
.I hope this incomplete answer is enough to get you started.