News for hackers. Stuff that matters.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by halayli on Tuesday May 05, 2015 @01:59PM (#9493921)
An enum, short for enumeration, shouldn't hold data, else don't call it an enum. It's no longer an enumeration, it's a data structure.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by kinghajj on Tuesday May 05, 2015 @02:07PM (#9493964)
Rust's enum is a natural extension to the common notion of enumerated types to ADTs: http://en.wikipedia.org/wiki/Enumerated_type#Algebraic_data_....
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by halayli on Tuesday May 05, 2015 @03:01PM (#9494263)
If Rust wants to win C/C++ developers, it shouldn't surprise them a lot.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by barosl on Tuesday May 05, 2015 @03:30PM (#9494421)
I would say that the reason it is named `enum` is exactly not to surprise them. While learning Haskell, I had used `data` several times, but never grokked its true meaning. The naming of `enum` in Rust helped me finally understand what ADTs are, and thus also made me truly understand what Haskell's `data` is. I really appreciate Rust for trying to introduce a certain concept with the existing names.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by kinghajj on Tuesday May 05, 2015 @03:18PM (#9494350)
Well it shouldn't be surprising, as Rust's enum behaves pretty much like a C/C++ one if all cases are nullary. The only changes are syntactical ("EnumType::Variant" instead of just "Variant", unless you "use EnumType::*"). In fact, it's exactly because they didn't want to be surprising that they used "enum" instead of something else, like "data" in Haskell.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by Dewie3 on Tuesday May 05, 2015 @03:58PM (#9494577)
They already chose to try to appeal to those developers by calling it "enum". And that doesn't sound like a good motivation to me: how hard is it to learn something like algebraic data types, compared to learning about lifetimes? It's like the choice to use angle brackets for generics - if the intent is to be easy for programmers with a certain background, that only lures them in with a false sense of familiarity. Because something like angle brackets over square brackets is, again, a superficial and easy thing to learn compared to any of the semantic stuff.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by pcwalton on Tuesday May 05, 2015 @03:11PM (#9494306)
> An enum, short for enumeration, shouldn't hold data, else don't call it an enum.

They can in Java. Java's about as mainstream of a programming language as you can think of.

Re:Virtual Structs Part 1: Where Rust’s Enum Shines by taeric on Tuesday May 05, 2015 @03:47PM (#9494518)
Not in the same way. In Java, you can have an enum that has some data placed on it, at a per value basis. You can not have an enum where different instances of the same value have different values attached to it.

That is, Enum.A will always be Enum.A with the same data on it at all times in Java. This is not the case for ADTs.

Re:Virtual Structs Part 1: Where Rust’s Enum Shines by pcwalton on Tuesday May 05, 2015 @04:23PM (#9494729)
Sure, but having enums with data is not per se out of the ordinary in mainstream languages.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by vbezhenar on Tuesday May 05, 2015 @02:05PM (#9493953)
Swift uses the same terminology. Probably meaning of enum will include ADT.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines by Dewie3 on Tuesday May 05, 2015 @02:28PM (#9494068)
I agree that the name seems misleadingly specific: it's named after a type of construct which it subsumes.

In cases like this I think it is better to call it by a more generic name rather than a specific name which it really subsumes (like Haskell using the `data` keyword for algebraic data type definitions).