Re:Algebraic Data Types: Things I wish someone had explained...
by akavi on Tuesday November 19, 2019 @10:43AM
(#21574060)
They're not present in the dominant statically typed languages (C/C++/C#/Java/Go) and not really a thing in dynamic languages generally, and so the vast majority of programmers never encounter the concept.
[ Parent
| on HN ]
Re:Algebraic Data Types: Things I wish someone had explained...
by pmontra on Tuesday November 19, 2019 @11:01AM
(#21574333)
Well, Pascal has been dominant for a short time before C and its family really took off. But that was such a long time ago that I kind of forgot about it. C (without ++) was nice because you could write code without too much boilerplate compare to Pascal and it was noticeably faster (computers were slow.) However any mistake with pointers could crash the computer if it was a DOS PC and not a UNIX workstation.
Re:Algebraic Data Types: Things I wish someone had explained...
by thestoicattack on Tuesday November 19, 2019 @11:55AM
(#21575150)
C++ has std::variant, but that's pretty new.
Re:Algebraic Data Types: Things I wish someone had explained...
by Sniffnoy on Tuesday November 19, 2019 @02:05PM
(#21576879)
My understanding is that's not really a sum type, though -- e.g., you couldn't use it to add a type to itself, only to add distinct types to each other.
Re:Algebraic Data Types: Things I wish someone had explained...
by edflsafoiewq on Tuesday November 19, 2019 @04:30PM
(#21578517)
No, you can add a type to itself (that is a pain in the ass though). You might be thinking of the fact that it may not hold a value (eg. if an exception is thrown while moving into it), but they made it as close to a sum as they could given the nature of C++.