Live data from Hacker News

Official proposal for Type Unions in C#

github.com

151–160 of 315 posts

Re: Official proposal for Type Unions in C#

#151

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

For me it's Elixir / Golang and Rust. Between these 3 I can serve all needs.

Re: Official proposal for Type Unions in C#

#153

Earlier quoted context omitted.

> but its in the hands of microsoft and microsoft didn't really care much about building a community or getting it to work natively in other OSes/toolchains. That statement was true - until 2016. Times change, Microsoft changed.

Nah, people continue to pick Java or Go when they want to build their enterprise systems if they're not already married to Microsoft. There's not a single widely distributed infra application in C# out there. When people want to build stuff like kafkas, kubernetes, consuls, they still go to Java/Go/C++.

> There's not a single widely distributed infra application in C# out there.

If you’ve used Wi-Fi in a hotel it’s very likely you’ve used a C# app. Is that “infra” and “widely distributed” enough?

Re: Official proposal for Type Unions in C#

#154

Even dotnet is looking at implementing type unions, why can't Dart finally agree on adding this aswell!?

We added sum types and exhaustive pattern matching in Dart 3.0. Union types (what the proposal here calls "ad hoc unions") are a separate, much harder feature whose value proposition is less clear. The cost of adding a new kind to the type system is quite large because it impacts method resolution, overriding, type inference, subtyping, least upper bound, generics, type promotion, etc. It can be worth it (for example…

Thanks, I appreciate the explanation a lot! I find losing the type hints because I am forced to type something as "dynamic" is a bummer, I hope exhaustive pattern matching solves cases like these: https://github.com/pocketbase/dart-sdk/blob/master/lib/src/a...

Related issue: https://github.com/dart-lang/language/issues/83

Re: Official proposal for Type Unions in C#

#155
I very much hope to see this (or similar) in C# soon. It’s not make or break for me, but it would certainly help make for cleaner, smaller codebases — I’ve sorely missed it in the past, but only a couple times. My context is being a former hard-core C++ person who switched to .Net and AWS pretty-much cold turkey.

Edit: typo

Re: Official proposal for Type Unions in C#

#156
post #16

Earlier quoted context omitted.

TypeScript has "union types". This proposal refers to them as "ad hoc unions". I don't think "type union" is a term of the art - at least I haven't heard it before. It seems to be something the C# people are making up to describe sum types.

> I don't think "type union" is a term of the art "sum type" is the term of art in Computer Science theory, but "union type" is also used. See https://en.wikipedia.org/wiki/Type_theory#Sum_type https://en.wikipedia.org/wiki/Tagged_union

At this point, calling it by its correct name (Sum Types) would leave them looking stupid for not using the correct name (Product Types) for their “records”

Re: Official proposal for Type Unions in C#

#157

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

I've been writing C, C++, C# and some js/sql/ts/python for money. Lua for lulz. And *nothing* gets even fucking close in terms of productivity to C#. Great language, mature and robust ecosystem with sane compilation times and great tooling: package manager, test runner, strong debugger, one CLI with almost all tools needed. I wish C++ was half as enjoyable as C# is.

I'm a Linux user who prefers open-source tools. I not a fan of Microsoft's programs, tools, editors, etc.

What would you suggest I do to be productive with C#?

Re: Official proposal for Type Unions in C#

#158

Earlier quoted context omitted.

I've been writing C, C++, C# and some js/sql/ts/python for money. Lua for lulz. And *nothing* gets even fucking close in terms of productivity to C#. Great language, mature and robust ecosystem with sane compilation times and great tooling: package manager, test runner, strong debugger, one CLI with almost all tools needed. I wish C++ was half as enjoyable as C# is.

I'm a Linux user who prefers open-source tools. I not a fan of Microsoft's programs, tools, editors, etc. What would you suggest I do to be productive with C#?

JetBrains Rider

Re: Official proposal for Type Unions in C#

#159

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

I was disappointed with Rust not being able to do ad-hoc unions, as well as the flippant you don't need that mentality of the community.

Re: Official proposal for Type Unions in C#

#160
post #7
post #3

Huh, I did F# for years with discriminated unions, and I guess I just assumed C# would have had them by now. I know not everyone likes them, but for typed languages I find it extremely hard to go back to languages without ADTs of some kind. I do Java for my current job, and Java is generally fine enough, but it's a little annoying when I have to do whacky workarounds with wrapper classes to get something that would b…

Good news is that you can achieve this with relatively little boilerplate in Java with sealed interfaces and records now. Relative to Java that is

Java can't do the ad-hoc mixing of types from different libraries, which is something I've wanted/needed for some ORM+expressions work I was doing. I really like where C# is going with this. Hopefully it will accelerate continuation of the evolution of Java.

I'm almost of the mind to use F# or C# instead of waiting.

Post reply on HN