News for hackers. Stuff that matters.
Re:Tagged unions, or ‘variants’, in C by yorwba on Monday June 26, 2017 @06:35AM (#14635655)
Tagged unions are an implementation of variants using a discriminating tag and a union type.

Variants are sometimes called sum types to emphasize the duality with product types (tuples).

Type classes are a completely unrelated concept, as others have already commented. They are more like vtables in C++: providing functions to operate on an otherwise opaque object.

Re:Tagged unions, or ‘variants’, in C by k__ on Monday June 26, 2017 @06:39AM (#14635672)
Ah okay.

I thought they were the Haskell equivalent.

I also don't know what vtables are, haha.

Re:Tagged unions, or ‘variants’, in C by klodolph on Monday June 26, 2017 @06:59AM (#14635754)
I don't want to be that guy but there is pretty solid explanation of vtables if you do a web search.

Some of the language also derives from either more traditional set theory (union, disjoint union, discriminated union) or from category theory (sum, coproduct) even though all of these things might mean the same concept in this particular case. Category theory is comparatively "new" (barely 70 years old) and so older works and languages tend not to use it.

Re:Tagged unions, or ‘variants’, in C by ozzmotik on Monday June 26, 2017 @08:32AM (#14636222)
nothing wrong with being that guy but at the same time there's also nothing wrong with admitting you don't know what something is before you go and look it up. i don't want to be that guy but the poster you responded to didn't ask what they were, only stated that they don't know what they are. im sure if they were curious enough and thought it relevant enough to their knowledge base they would go look it up of their own accord.

also, another point I'd really like to bring up is, while in general im comfortable with doing research and learning something from resources on the web, some people are less confident in their abilities to understand something and would prefer to ask another human being to explain it so they can open up the possibility of discussion if they don't particularly understand the verbiage or concepts contained within the answer; it's much easier to ask a person a question than to ask an article or a tutorial one when said resource may not even be actively maintained or monitored anymore and social interaction may have potentially died down on it.

im not trying to really complain as I do believe everyone should really take the time to do their own research and come to their own conclusions, but having someone they can ask is useful in and of itself in the same way having a professor in college you can ask to clarify is being useful. if you don't have another individual that is knowledgeable about the concepts you're unsure about your perception of to potentially confirm or deny your conclusions, then you're basically operating on unknown unknowns, and as far as I understand, in intellectual practice, it is the desire of the practitioner to eliminate any possible unknown unknowns through whatever means necessary and account for all possibilities and deviations.

but yeah, Google first then ask questions!

Re:Tagged unions, or ‘variants’, in C by k__ on Monday June 26, 2017 @08:53AM (#14636347)
Sure, problem is when you 'think' you know something, but you don't, as I thought type classes are equivalent to variants :D
Re:Tagged unions, or ‘variants’, in C by tome on Monday June 26, 2017 @10:40AM (#14637134)
I don't think the word "sum" for disjoint union comes from category theory. It must be older than that.