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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With