F* 中的应用函子:类型检查错误

Applicative functor in F*: Type checking error

作为尝试熟悉 F* 的实验,我尝试实现一个应用函子。我陷入了一个看起来很奇怪的类型检查错误。我还不确定这是由于我不知道的类型检查中的某些功能/逻辑,还是由真正的错误引起的。

这是给我带来麻烦的代码部分:

module Test

noeq type test : Type -> Type =
    | Apply : test ('a -> 'b) -> test 'a -> test 'b

val apply : test ('a -> 'b) -> test 'a -> test 'b
let apply f x = Apply f x

这是相应的错误:

Test(7,24-7,25): (Error 54) Test.test 'a is not a subtype of the expected type Test.test 'a (see also Test(7,12-7,13))
1 error was reported (see above)

有人可以向我指出我所缺少的吗?类型统一的行为是否受子类型影响?还是应该进行类型检查,这是一个编译器错误?

我相信你没有强制执行归纳法的宇宙不等式约束。

以下代码将进行类型检查:

noeq type test : Type0 -> Type =
    | Apply : test ('a -> 'b) -> test 'a -> test 'b

val apply : test ('a -> 'b) -> test 'a -> test 'b
let apply f x = Apply f x

注意我在第一行添加的0

这是可行的,因为这表明第一个 Type0 处于比 Type 更低的宇宙中(我相信它本身意味着任何宇宙)。 在您的情况下,F* 不知道如何比较这两种类型的宇宙,因此失败了。

如果您编写了 noeq type test : Type -> Type0,您会看到稍微好一点的错误消息:"Failed to solve universe inequalities for inductives"。所以我把错误信息归咎于此。

如果解释不够准确,我深表歉意,我不是 PL 人...:)