Hacker News new | past | comments | ask | show | jobs | submit login

Newbie here. What are the differences with Swift Enumerations?



Compared to Rust enumerations, they are one and the same. In fact, looking at the documentation for Swift Enumerations yields this little nugget:

You can define Swift enumerations to store associated values of any given type, and the value types can be different for each case of the enumeration if needed. Enumerations similar to these are known as discriminated unions, tagged unions, or variants in other programming languages. [1]

Haskell and other ML family languages also have similar constructs, although these are usually modelled using "Algebraic Data Types", or "sum types". [2] [3]

[1]: https://developer.apple.com/library/content/documentation/Sw...

[2]: https://wiki.haskell.org/Algebraic_data_type

[3]: https://www.schoolofhaskell.com/school/to-infinity-and-beyon...


Details (some features they provide or can provide), Swift's enumerations and Rust's enum are both implementation of the older concept of Algebraic Data Types (ADT), which can be found in pretty much any language inspired by ML (directly or indirectly).


Swift enums are basically the same as Rust ones. The differences between C++ variants and Rust enums listed in the blog post apply between C++ and Swift too.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: