bob*_*bob 4 haskell gadt higher-rank-types newtype
Yoneda
只要设置了更高级别的扩展名,就具有有效的类型:
newtype Yoneda f a = Yoneda (forall b. (a -> b) -> f b)
这产生了类型(forall b. (a -> b) -> f b) -> Yoneda f a
。
b
由消费者挑选Yoneda
,因此不会出现在newtype
声明的 LHS 上。
Coyoneda
但是,对我来说没有意义:
data Coyoneda f a = forall b. Coyoneda (b -> a) (f b)
这产生(b -> a) -> f b -> Coyoneda f a
.
b
被明确量化,但量词似乎不在正确位置呈现类型变量等级 2。 尽管如此b
,并未在data
声明的 LHS 中列出。那是什么?几乎是存在的?这只是一个没有受过教育的猜测,因为我不太了解存在量词,并假设 Haskell 不支持它们。
data Coyoneda f a = forall b. Coyoneda (b -> a) (f b)
Run Code Online (Sandbox Code Playgroud)
也可以用 GADT 语法编写:
data Coyoneda f a where
Coyoneda :: forall b. (b -> a) -> f b -> Coyoneda f a
Run Code Online (Sandbox Code Playgroud)
显式量化是可选的。
Coyoneda :: (b -> a) -> f b -> Coyoneda f a
Coyoneda :: forall f a b. (b -> a) -> f b -> Coyoneda f a
Run Code Online (Sandbox Code Playgroud)
所以你猜对了:b
这里是存在量化的,因为它没有出现在Coyoneda
数据构造函数的结果类型中。