Live data from Hacker News

.NET (OK, C#) finally gets union types

andrewlock.net

241–250 of 300 posts

Re: .NET (OK, C#) finally gets union types

#241
sadly there is no ad hoc way of defining them. I do not care if they are boxed. I just want to say Success or Error1 or Error 2. Maybe I can live with or | or other stuff but not having ad hoc unions is basically not cool.

Re: .NET (OK, C#) finally gets union types

#242
post #237
post #209

Earlier quoted context omitted.

By Haskell's type system do you mean with all the GHC extensions? Because TypeScript has structural sub-typing, while standard Haskell (eg. `A | B | C`) has neither subtyping nor structural typing, which both are very useful features for safe "integration/glue" type of programs. (String) literals form a fundamental part of the TS "row polymorphism" (record types) and eg. tuple union type implementation. You can type…

> By Haskell's type system do you mean with all the GHC extensions? No? What extensions does `A | B | C` require? > Haskell has neither subtyping nor structural typing Is subtyping back in? Good news for Java and C++. Re structural typing, I would ask what behaviour you're after, specifically. For example, this is a valid, typed Haskell function for any two values that can be added, including any user-defined ones: a…

OCaml and Scala, both also famously strongly typed functional languages, also have structural typing (OCaml even has many different kinds at many different levels!). Mainstream, Go is based on structural (interface) typing.

The Person/Wine example is a pointless strawman. That's not what structural typing is generally used for.

The entire comment is basically making up strawmans... I didn't give practical examples to save space, obviously, it was just to disambiguate what I meant.

TypeScript has several runtime-safe advanced validators based on its type system (most well-known being Zod), capable of enforcing types similar to what I provided.

To conclude, these type system features were added by multiple experienced language designers for a reason, to languages that already had functional ADTs, so going "huh but what are these even useful for?!" to me sounds a bit clueless (or argumentative), so I don't see a productive continuation to this discussion.

Re: .NET (OK, C#) finally gets union types

#243
post #43

Earlier quoted context omitted.

I am all for minimalism but "If you come from one codebase to another codebase by a different team it’s close to learning a completely new language" I really don't agree. It's not that big. Just sounds like a skill issue

Sure. Maybe it was a skill Issue. I switched between dozens of similar codebases over a period of 3-4 years (pre AI) when I was consulting and did multiple projects in multiple languages (well, only 1 in rust). In my experience switching between the C# projects was always the worst. The codebase semantics diverged in ways I simply didn’t see in the Java/C++ codebases.

> C++ codebases

Now this one sounds almost unbelievable :). I’ve yet to see 3 or more C++ codebases using the same language feature set.

Re: .NET (OK, C#) finally gets union types

#244
post #242
post #237

Earlier quoted context omitted.

> By Haskell's type system do you mean with all the GHC extensions? No? What extensions does `A | B | C` require? > Haskell has neither subtyping nor structural typing Is subtyping back in? Good news for Java and C++. Re structural typing, I would ask what behaviour you're after, specifically. For example, this is a valid, typed Haskell function for any two values that can be added, including any user-defined ones: a…

OCaml and Scala, both also famously strongly typed functional languages, also have structural typing (OCaml even has many different kinds at many different levels!). Mainstream, Go is based on structural (interface) typing. The Person/Wine example is a pointless strawman. That's not what structural typing is generally used for. The entire comment is basically making up strawmans... I didn't give practical examples to…

Haha, I knew you'd bring up Go. I even considered pre-emptively dropping Rust and Zig as counterexamples. I think most people who favour static typing consider the duck-typed interfaces of Go to be a mistake. Personally, I consider all of Go to be a mistake.

> these type system features were added by multiple experienced language designers for a reason

Oooh, an appeal to authority, where that authority isn't even named. I'll have you know a famous queen told me you're wrong on this, also for "a reason".

> TypeScript has several runtime-safe advanced validators based on its type system (most well-known being Zod), capable of enforcing types similar to what I provided.

Right, so TS typing is so amazing it requires runtime parser libraries from NPM, and Haskell is less sophisticated because it's not stringly typed.

You realise the entire, complete, exhaustive runtime schema for your zero-first non-empty integer array example looks like this in Haskell, right?

    sch (0:_) = True
    sch _ = False
That's a complete function that somehow manages to work without pulling in NPM dependencies. The best JavaScript minds of our generation remain baffled.

> The Person/Wine example is a pointless strawman

> I didn't give practical examples to save space, obviously, it was just to disambiguate what I meant.

So when you use illustrative examples, it is to "disambiguate what you meant" (huh?), and when I do it, they're "pointless strawmen". A little hypocritical, no?

> a bit ignorant

Honestly, I don't think you know what you're talking about at all. You clearly hadn't even read my comment when you started replying with Python and TS examples... that were already in my comment.

It also really sounds like you're using string literals to type input without properly parsing it, which is just a terrible idea. Haskell's type system is designed precisely to protect you from this sort of mistake. [0] No, you're not always going to get what you expect. No, your JS program will never let you know that's the case. No, a sane type system does not require mainlining runtime parser libraries from the biohazardous oceans of NPM. A schema in Haskell is going to be significantly shorter and sounder than anything in Zod, and you don't need a library for it.

As I said above, TS' type system makes sense for a type system bolted onto a dynamic language post facto. TS needs to more tightly link (even mildly conflate) values and types, since it needs to do a lot of clever narrowing to figure out what mad ball of JS it is dealing with at any given time. Haskell does not operate under any such constraint.

> I don't see a productive continuation to this discussion.

Phew. Timesaver.

Of course the irony of all this is that I use TS daily, and Haskell quite rarely.

[0] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Re: .NET (OK, C#) finally gets union types

#245
post #215

Earlier quoted context omitted.

Except one of the milestones for .NET 11 is to offer similar mechanisms for async/await.

Link?

It starts with the experiment,

https://github.com/dotnet/runtimelab/issues/2398

Which ended with,

> We have chosen to place the green threads experiment on hold and instead keep improving the existing (async/await) model for developing asynchronous code in .NET. This decision is primarily due to concerns about introducing a new programming model. We can likely provide more value to our users by improving the async model we already have. We will continue to monitor industry trends in this field.

Now three years later we have,

https://github.com/dotnet/core/blob/main/release-notes/11.0/...

> Runtime async is a major runtime feature in .NET 11 that introduces new runtime-level infrastructure for async methods. The goal is to improve tooling and performance for async-heavy codepaths. For more details and to track progress, see the Runtime Async epic issue.

Re: .NET (OK, C#) finally gets union types

#246

Earlier quoted context omitted.

Is it called "trio" state because 3 of the 5 states are not supported? I also like how True is -1. Beautiful all around!

-1 means every single bit is 1, the truest possible value.

I’m having a surprisingly difficult time deciding if I strongly agree or disagree with this statement.

Re: .NET (OK, C#) finally gets union types

#247
post #246

Earlier quoted context omitted.

-1 means every single bit is 1, the truest possible value.

I’m having a surprisingly difficult time deciding if I strongly agree or disagree with this statement.

I know VB used -1 as the truth value, not sure about other languages.

Re: .NET (OK, C#) finally gets union types

#248
post #244
post #242

Earlier quoted context omitted.

OCaml and Scala, both also famously strongly typed functional languages, also have structural typing (OCaml even has many different kinds at many different levels!). Mainstream, Go is based on structural (interface) typing. The Person/Wine example is a pointless strawman. That's not what structural typing is generally used for. The entire comment is basically making up strawmans... I didn't give practical examples to…

Haha, I knew you'd bring up Go. I even considered pre-emptively dropping Rust and Zig as counterexamples. I think most people who favour static typing consider the duck-typed interfaces of Go to be a mistake. Personally, I consider all of Go to be a mistake. > these type system features were added by multiple experienced language designers for a reason Oooh, an appeal to authority, where that authority isn't even nam…

Yeah, you're just continuing to take whatever was written argumentatively/maliciously as predicted.

Does not seem like this:

> Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith.

> Personally, I consider all of Go to be a mistake.

You also consider Scala and OCaml to be mistakes? Because all of what I've mentioned also works in a very similar way in Scala.

> an appeal to authority

No, I didn't appeal to authority. It's the opposite - it's statistics. Multiple experienced language designers don't add features later for nothing. For a similar process, see eg. closures getting added to every mainstream language.

> complete, exhaustive runtime schema

Again, I wasn't talking about runtime schemas, but types. I only mentioned runtime as a counterpoint to the false statement that TypeScript doesn't enforce this. Only reducing this to runtime checking is a fallacy, again.

> A little hypocritical, no?

No, they aren't comparable since I wasn't using the examples as supports for an argument of whether X is better than Y. Strawmen involve argumentation.

> read my comment... examples... that were already in my comment

I read it in detail, the problem is you didn't really read my comment in detail, which illustrated both the subtyping and structural typing aspects (albeit trivially, yes), which yours didn't.

> You're also fairly clearly using string literals to type input without properly parsing it

Okay then, the arrogance of this is pretty astounding... You seem to know what I'm doing better than I am!

To be clear, I'm not doing any of that. And I've written Haskell way before I wrote any TypeScript.

Re: .NET (OK, C#) finally gets union types

#249
post #66

C# is my strongest and favorite language. That said, it's frustrating that the C# framework ecosystem lacks solid options. MAUI is especially half-baked, and I'm really starting to doubt whether I should continue using XAML

Same. I wish there was a good story for .NET UI on desktop, mobile, and web. I find Maui Blazor Hybrid to be pretty close. The desktop and mobile variants compile to a webview bound to native code (no WASM, no JS), and the Web variant compiled to WASM. Much leaner than Electron. Pretty clunky though last time I tried though that was three years ago.

Re: .NET (OK, C#) finally gets union types

#250
post #185

Earlier quoted context omitted.

C# was always better than Java as a language. The strength of Java is the ecosystem, and Java being open source and cross-platform from the beginning.

Language design isn't just about adding every possible feature. For example, someone mentioned operator overloading. As someone who has written a lot of Scala, I think operator overloading would be a very bad feature for an enterprise language like Java which needs to be consistent above all else. I never understood the obsession some people have with the C# vs Java debate anyway. Generally, both languages are very g…

> I think operator overloading would be a very bad feature for an enterprise language like Java which needs to be consistent above all else.

Operator overloading increases consistency. Instead of having

  int a = b + c;
  CustomNumberType x = y.add(z);
you have

  int a = b + c;
  CustomNumberType x = y + z;
Post reply on HN