4 ms·
Is it possible to write a reusable version of something like this in Go without using interface{}?
by rvense 9y ago
Is it possible to write a reusable version of something like this in Go without using interface{}?
- masklinn 9y agoIf "static codegen" is considered OK, then I guess yes, and I guess you can use The Thing[0] to even make them look like actual generics. Every user of the library will need to run codegen to post-process their source files and generate the relevant instantiations of the "generic" collection. [0] https://www.reddit.com/r/rust/comments/5penft/parallelizing_enjarify_in_go_and_rust/dcsq64p/?context=42 https://www.reddit.com/r/rust/comments/5penft/parallelizing_...
- nine_k 9y agoThen I could take almost any reasonable language, and transpile it to Go source. This worked for years for Javascript 5, and for C before that, and for Fortran even before that. In either case, the reason was that the target language was considered not expressive enough, though ubiquitous.
- TheCoelacanth 9y agoSo you can do it in Go in the same sense that you can do it in assembly language.
- masklinn 9y agoExactly.
- randomdata 9y agoIt is, of course, possible to write reusable containers without interface{}[1], but it is not exactly a replacement for proper generics. [1] https://play.golang.org/p/2GZRkMJ_Mf https://play.golang.org/p/2GZRkMJ_Mf