3 ms·
Can I get an ELI5 on erased, specialized, and existential types?
by throwaway894345 3y ago
Can I get an ELI5 on erased, specialized, and existential types?
- Ericson2314 3y agospecialized: always substitute every type variable until they are all gone, creates many different "specializations" or "instantiations". This is like Rust erased: just ignore the type variables for compilation. This is like the typescript -> javascript compilation. (Also how Java, Scala, Haskell, OCaml, etc. type paramters work) Existential: "there exists a type such that..." see https://en.wikipedia.org/wiki/Existential_quantification https://en.wikipedia.org/wiki/Existential_quantification https://en.wikipedia.org/wiki/System_F https://en.wikipedia.org/wiki/System_F
- avgcorrection 3y agoIs “erased” how Haskell typeclasses work?
- tome 3y agoNo, the opposite. They're either specialized (when they can be) or (effectively) existential (when they must be). That is, the compiler either inlines the specific definition of the type class methods if it knows them, or passes them around at run time.
- Ericson2314 3y agoAgreed, except I would not call it "existential" C++ stores references to dictionaries from/with the things they describe, that's "existential" Haskell passes in extra parmeters that are dictionaries and doesn't (except for user-written code that does) keep around extra references to them. That's more like "universal" than "existential".
- Ericson2314 3y agoErased is how types in Haskell work. Type classes are compiled as "dictionaries": structs of methods. Sometimes they can specialize them (just pull the thing out of the dictionary statically), but in general they become that extra parameters at run time.