haskell - Coyoneda 没有更高等级的类型,但实际上它是什么类型?

标签 haskell gadt newtype higher-rank-types

Yoneda只要设置了更高级别的扩展名,就具有有效的类型:newtype Yoneda f a = Yoneda (forall b. (a -> b) -> f b)产生类型 (forall b. (a -> b) -> f b) -> Yoneda f a .bYoneda 的消费者挑选因此不会出现在 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/

相关文章:

javascript - 国外进口新型品种创历史新高

reference - 如何将借来的值包装在也是借来的值的新类型中?

Haskell 继承、数据、构造函数

haskell - 将简单类型语言的无类型 AST 转换为 GADT

haskell - 重用多个值构造函数模式匹配时避免重复代码

haskell - 使用 Hedgehog(或任何其他基于属性的测试框架)生成随机 GADT 的最安全方法

OCaml - GADT - bool 表达式

haskell - 隐式类型强制?

haskell - Reactive-Banana 中溢出函数的事件处理顺序是什么?

unix - haskell System.Process.createProcess 重定向 stdout 和 stderr