4 ms·
Unions is a problem for garbage collectors. It is difficult to know if it contains a reference or a value. Though Go should have a solution for your use case. T
by chmike 15y ago
Unions is a problem for garbage collectors. It is difficult to know if it contains a reference or a value.
Though Go should have a solution for your use case. The only one I see is polymorphism. Thus a stack of references to different instances of the same class.
- ootachi 15y agoDiscriminated (type-safe) unions like ML and Haskell have are no problem for garbage collectors: you simply assign one ID to each variant of the union, and prefix the data with the ID corresponding to the variant in use. You can simulate ML-style unions in Go with interfaces and downcasts, or the reflect package (basically like case classes in Scala, but without the exhaustiveness checking). Unfortunately, downcasts in Go (and interfaces generally) are slow.