hmemcpy / milewski-ctfp-pdf

Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source
https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
Other
10.84k stars 575 forks source link

Acknowledge std::variant #268

Open elshize opened 3 years ago

elshize commented 3 years ago

In section 5.6 Coproduct, there is the first mention of C++ union and how they are not tagged unions, and later it mentions boost::variant. However, we've had std::variant for a while now, so it might be a good idea to mention that.

Later on, when talking about sum types (6.2), it says:

You will rarely see union used as a sum type in C++ because of severe limitations [...] You can't even put a std::string into a union.

Though indeed I variants are definitely not as common as inheritance, this paragraphs ignores the fact that you can easily define a sum type with std::variant in C++17 and up, and you can put std::string in it as well.

If anything, I would say something like:

You rarely see unions in C++ because of the lack of pattern matching support in the language.

Anyway, it's not a big deal but it could be misleading for someone who isn't familiar with C++.