Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 737
Robert Zaremba Avatar asked Aug 03 '14 10:08

Robert Zaremba


2 Answers

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.

like image 137
GS - Apologise to Monica Avatar answered Oct 28 '22 14:10

GS - Apologise to Monica


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.

like image 22
MigMit Avatar answered Oct 28 '22 14:10

MigMit