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)
也可以用 GADT 语法编写:data Coyoneda f a where
Coyoneda :: forall b. (b -> a) -> f b -> Coyoneda f a
显式量化是可选的。Coyoneda :: (b -> a) -> f b -> Coyoneda f a
Coyoneda :: forall f a b. (b -> a) -> f b -> Coyoneda f a
所以你猜对了:b
这里是存在量化的,因为它没有出现在 Coyoneda
的结果类型中数据构造器。
关于haskell - Coyoneda 没有更高等级的类型,但实际上它是什么类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68670779/