Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Enums are Sum Types, which are a type of ADT[1]. Tuples are a Product Types, which are another type of ADT[2]; Sum Types are so called because when you add one to that, you add just one more possibility (It could be A,B now it can be A,B,C). Product Types, on the other hand, give out possibilities based on their Product, so if you add a new property, you multiply it (A,B can both be two things, so you have 4 possibilities, if you add C that can also be two things, then you now have 8 possibilities).

This is a good explanation: https://jrsinclair.com/articles/2019/algebraic-data-types-wh...

[1]https://en.wikipedia.org/wiki/Tagged_union

[2]https://en.wikipedia.org/wiki/Product_type



I found https://guide.elm-lang.org/appendix/types_as_sets.html is friendly describing the what and why.




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

Search: