Finally C# will have a more idiomatic way to represent this classic code example from “The Daily WTF” in 2005 — enum Bool { True, False, FileNotFound }; See https://thedailywtf.com/articles/what_is_truth_0x3f_
.NET (OK, C#) finally gets union types
141–150 of 300 posts
Re: .NET (OK, C#) finally gets union types
#142AFAICT, this means you won’t be able to define Either , which is definitely a thing you sometimes want to do.
Well it is a type union. The union of string and string is just string.
Re: .NET (OK, C#) finally gets union types
#143Re: .NET (OK, C#) finally gets union types
#144Earlier quoted context omitted.
> That's like saying Haskell is really an imperative language just because it's written in C I honestly don't even remotely understand how you got to that from what I wrote. Unions already have a definition. You cannot go around claiming that technically unions are not unions (and that "most people don't know" this), because theory X or Y overloads the term union to refer to some unrelated concept. That's fine and we…
> You cannot go around claiming that 'technically' unions are not unions I never said this. I said that there are two different kinds of unions with quite different definitions and behaviors. > A tagged union is so called because it is a union (overlapping memory) with a field (a tag) containing a discriminator (aka discriminated union). An untagged union is a union without this tag. That alone doesn't sufficiently d…
Re: .NET (OK, C#) finally gets union types
#145AFAICT, this means you won’t be able to define Either , which is definitely a thing you sometimes want to do.
Re: .NET (OK, C#) finally gets union types
#146Earlier quoted context omitted.
> That's like saying Haskell is really an imperative language just because it's written in C I honestly don't even remotely understand how you got to that from what I wrote. Unions already have a definition. You cannot go around claiming that technically unions are not unions (and that "most people don't know" this), because theory X or Y overloads the term union to refer to some unrelated concept. That's fine and we…
> You cannot go around claiming that 'technically' unions are not unions I never said this. I said that there are two different kinds of unions with quite different definitions and behaviors. > A tagged union is so called because it is a union (overlapping memory) with a field (a tag) containing a discriminator (aka discriminated union). An untagged union is a union without this tag. That alone doesn't sufficiently d…
It's hard to know what to say to this. Tagged unions are not tagged unions, even if they are literal tagged unions? What?
I reiterate what I said in my previous comment, you're not using the ordinary definition of the term union, and this is causing confusion. A union may or may not be a "union" as understood within various academic type theories, that really depends on how any given theory defines that word, which can be any way it wants. But a union is a CS concept with a clearly understood meaning, and when used without added context to suggest it is to be interpreted in some theoretical way, it is understood in that ordinary way.
OP's article is clearly using 'union' to mean tagged unions - he even shows off their implementation, with a tag. The author assumes that his audience will understand what he's talking about when he uses the word union, and it's not causing anyone trouble in this comments section. The fact that alternative definitions within various theoretical paradigms is very nice, bless their hearts, but not really relevant.
You may prefer other definitions to the usual CS definition, that's certainly your prerogative, but - again - that's hardly grounds for taking an article and comment section that's using the commonplace meaning, and appearing to lecture others for failing to adhere to your idiosyncratic standards for what a union must be.
Re: .NET (OK, C#) finally gets union types
#147Earlier quoted context omitted.
A common use case for the sum type is to define a Result (or Either) type. Now, C# not having checked exceptions is not as much in need for one as Java is, but I could still imagine it being useful for stream like constructs.
yeah this is the one I've considered as being mildly compelling. But don't we lose the fun of having exception handling as separate to the happy path?
Re: .NET (OK, C#) finally gets union types
#148I love C# and in every iteration we're getting more and more features to get C-like performance in a lot of scenarios. C# does it really well because if your problem isn't performance/memory-constrained, you can ignore these features and fallback on the language's natural ease of use.
Do you think by now C# has left Java behind in features and performance?
Re: .NET (OK, C#) finally gets union types
#149Earlier quoted context omitted.
Discriminated union types are a really fundamental building block of a type system. It's a sad state of matters that many mainstream languages don't have them.
ok, so what problems do they help me solve that I can't already solve? Is it just that we can make code more concise or am I missing a trick somewhere?
Re: .NET (OK, C#) finally gets union types
#150Earlier quoted context omitted.
> You cannot go around claiming that 'technically' unions are not unions I never said this. I said that there are two different kinds of unions with quite different definitions and behaviors. > A tagged union is so called because it is a union (overlapping memory) with a field (a tag) containing a discriminator (aka discriminated union). An untagged union is a union without this tag. That alone doesn't sufficiently d…
> Maybe they are implemented similarly under the hood It's hard to know what to say to this. Tagged unions are not tagged unions, even if they are literal tagged unions? What? I reiterate what I said in my previous comment, you're not using the ordinary definition of the term union, and this is causing confusion. A union may or may not be a "union" as understood within various academic type theories, that really depe…