使用 CPS 将 ImpredicativeTypes 减少为 RankNTypes

Reducing ImpredicativeTypes to RankNTypes with CPS

这四种说法,哪一种是错误的?


编辑:我很惊讶这还不清楚。 data Maybe = Nothing | Just a 可以写成 type Maybe a = forall b. b -> (a -> b) -> bdata [] a = [] | a : [a] 可以写成 type [] a = forall b. b -> (a -> b -> b) -> b。 (与 maybefoldr 相比。)对于所有 newtypedata 定义,同样的事情应该是可能的,并且称为连续传递样式(CPS)。

据我所知,ghc 使用 RankNTypes 扩展正确实现了深度嵌套 forall(->) 类型的类型推断,但是ImpredicativeTypes,即使在 (->) 以外的类型构造函数的参数中也允许 forall,但已无可救药地被破坏。

但是你不能通过将所有 datanewtype 类型转换为它们的 CPS 形式,使用 RankNTypes 机制进行推理然后转换回data/newtype 表格?

None 个。使用 ImpredicativeTypes 的困难在于没有类型推断,需要用户提供明确的类型签名。您假设由于 RankNTypes 被广泛使用,类型推断通常适用于 RankNTypes,但那是 not true:

It is not possible to infer higher-rank types in general; type annotations must be supplied by the programmer in many cases.