简体   繁体   中英

GADT vs Existentially quantified types (*forall*)

One can use GADT to express Existentially quantified types .

I see that GADT is more generic - data-type-extensions , paragraph section 7.4.7

When it's better to use Existentially quantified types then GADT ? Are there any drawbacks using GADT compared to Existentially quantified types ?

GADTs came along later than existentials, and they generalise them. I'm not aware of any drawbacks and would always use GADT syntax in new code as it's much clearer.

The documentation confirms this:

Notice that GADT-style syntax generalises existential types.

If you use the newest version of GHC, then there are no drawbacks I'm aware of. But in older versions you could combine GADTs and GeneralizedNewtypeDeriving in a type-unsafe way. I don't think the same was possible with ExistentialQuantification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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