这是功能子类型关系的示例吗?
Is this an example of a functional subtype relationship?
From this video by Functional Programming Principles in Scala "4.5 Variance" 你可以看到一张幻灯片说,
Translated:
Say you have two function types:
type A = IntSet => NonEmpty
type B = NonEmtpy => IntSet
According to the Liskov Substitution Principle, which of the following should be true?
A <: B
(checked)
B <: A
A
and B
are unrelated.
视频声明类型 A
是类型 B
的子类型;但是,它是这么说的,
Type A satisfies the same contract as Type B if you give it a NonEmpty set it will give you back an IntSet, but it will actually satisfy more than B.
但事实并非如此,B 包含 NonEmpty 集,其中包含比 IntSet 更多。这个视频是不是直接错误和混淆了?
我认为 NonEmpty
是 IntSet
的子类型(也许在上一课中提到过?)根据 Odersky 说话的方式,听起来 NonEmpty
是 IntSet
的非空子集。因此 A
比 B
接受更多的参数值,并且 returns 比 B
接受更窄的值子集,一个具有附加属性的子集。
From this video by Functional Programming Principles in Scala "4.5 Variance" 你可以看到一张幻灯片说,
Translated:
Say you have two function types:
type A = IntSet => NonEmpty type B = NonEmtpy => IntSet
According to the Liskov Substitution Principle, which of the following should be true?
A <: B
(checked)B <: A
A
andB
are unrelated.
视频声明类型 A
是类型 B
的子类型;但是,它是这么说的,
Type A satisfies the same contract as Type B if you give it a NonEmpty set it will give you back an IntSet, but it will actually satisfy more than B.
但事实并非如此,B 包含 NonEmpty 集,其中包含比 IntSet 更多。这个视频是不是直接错误和混淆了?
我认为 NonEmpty
是 IntSet
的子类型(也许在上一课中提到过?)根据 Odersky 说话的方式,听起来 NonEmpty
是 IntSet
的非空子集。因此 A
比 B
接受更多的参数值,并且 returns 比 B
接受更窄的值子集,一个具有附加属性的子集。