Idris:记录中的隐式参数

Idris: Implicit parameters in records

当我尝试编译这个例子时

record R where
    f: () -> {t: Type} -> t

我收到这个错误:

Type mismatch between
        () -> t1 (Type of f)
and
        () -> t (Expected type)

Specifically:
        Type mismatch between
                t1
        and
                t

另一方面这个例子

record R where
    f: {t: Type} -> () -> t

工作正常。你能告诉我第一个有什么问题吗?

这是 Idris 中的一个错误:有时 -> 运算符不是右结合的:issue #4077.

要查看它,我们可以对记录语法进行脱糖处理:

data R : Type where
  MkR : (() -> {t : Type} -> t) -> R

现在我们需要手动实现 f 投影。原来

f : R -> (() -> {t : Type} -> t)
f (MkR g) = g

类型检查,但是

f : R -> () -> {t : Type} -> t
f (MkR g) = g

会。

在我看来,Idris 使用第一个变体将 record 脱糖为 data,因此出现了您观察到的错误。