News for hackers. Stuff that matters.
Re:Improving Interoperability Between Rust and C++ by throwaway894345 on Monday February 05, 2024 @02:53PM (#39266178)
Can I get an ELI5 on erased, specialized, and existential types?
Re:Improving Interoperability Between Rust and C++ by Ericson2314 on Monday February 05, 2024 @03:38PM (#39266815)
specialized: 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/System_F

Re:Improving Interoperability Between Rust and C++ by avgcorrection on Monday February 05, 2024 @04:03PM (#39267145)
Is “erased” how Haskell typeclasses work?
Re:Improving Interoperability Between Rust and C++ by tome on Monday February 05, 2024 @04:09PM (#39267212)
No, 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.
Re:Improving Interoperability Between Rust and C++ by Ericson2314 on Monday February 05, 2024 @05:09PM (#39267944)
Agreed, 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".

Re:Improving Interoperability Between Rust and C++ by Ericson2314 on Monday February 05, 2024 @04:29PM (#39267485)
Erased 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.