简体   繁体   English

GADT与存在量化类型(* forall *)

[英]GADT vs Existentially quantified types (*forall*)

One can use GADT to express Existentially quantified types . 可以使用GADT来表达存在量化类型

I see that GADT is more generic - data-type-extensions , paragraph section 7.4.7 我看到GADT更通用 - 数据类型扩展 ,第7.4.7节

When it's better to use Existentially quantified types then GADT ? 当使用存在量化类型然后GADT更好 Are there any drawbacks using GADT compared to Existentially quantified types ? 存在量化类型相比,使用GADT有任何缺点吗?

GADTs came along later than existentials, and they generalise them. GADT出现的时间晚于存在时,他们将它们概括为一般。 I'm not aware of any drawbacks and would always use GADT syntax in new code as it's much clearer. 我不知道任何缺点,并且总是在新代码中使用GADT语法,因为它更清晰。

The documentation confirms this: 文件证实了这一点:

Notice that GADT-style syntax generalises existential types. 请注意,GADT样式的语法概括了存在类型。

If you use the newest version of GHC, then there are no drawbacks I'm aware of. 如果您使用最新版本的GHC,那么我就没有任何缺点。 But in older versions you could combine GADTs and GeneralizedNewtypeDeriving in a type-unsafe way. 但在旧版本中,您可以以类型不安全的方式组合GADT和GeneralizedNewtypeDeriving。 I don't think the same was possible with ExistentialQuantification. 我不认为ExistentialQuantification也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM