4 ms·
Hey thanks for sharing this, I think this has lost track of the problem though, remember we're looking for the alternative to rust's: enum Shape {
by CraigJPerry 4y ago
Hey thanks for sharing this, I think this has lost track of the problem though, remember we're looking for the alternative to rust's:
enum Shape {
None,
Circle(radius: usize),
}
In your version we've lost the Shape concept, to make it more explicit, what's the idiomatic go version of:
enum Shape {
Circle(usize),
Rectangle{length: usize, breadth: usize},
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=03c26eceee80168ffd69518aeefcc8e6 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- preseinger 4y agoThere is no way to express an enum whose possible values are of different types. In Go code will typically "offer" concrete types, and "accept" abstract interfaces. Abstractions over concrete types are expressed by consumers who want to operate on those types, rather than producers who provide implementations of them. So your Shape would probably end up an interface defined by whatever consuming code wanted to treat Circles and Rectangles equivalently.