# Type Unions for C#
* [x] Proposed
* [ ] Prototype: [Not Started](pr/1)
* [ ] Implementation: [Not Started](pr/1)
* [ ] Specification: [Not Started](pr/1)
## Summary
[summary]: #summary
A proposal for type unions (aka discriminated unions) in C#.
## Motivation
When developing software you may encounter situations where the values that you want to store in a variable are not always the same kind each time through. While you are usually not concerned about storing strings and numbers in the same spot, you may need to store one of a few related types depending on what that data is meant to represent at that moment.
For example, your application may have both a customer and a supplier definition that share only some of the same properties and you may need to perform a similar operation on both in a fashion that depends on the differences.
Typically, this is where you might choose to distribute those specialized implementations into the types themselves and expose them through common abstract methods or interfaces. However, this is only good practice when those types exist primarily for the purpose of the operation or it makes sense for the operation to appear as an intrinsic part of the type. If the types have a broader purpose, polluting them with methods like this can be undesirable.
This file has been truncated. show original
A proposal for type unions (aka discriminated unions) in C#.
타입이 강조되는 함수형 언어는 대수(Algebraic)적 원리를 도입해 타입을 정의하는데요. 대수에서 ADT(Algebraic Data Type)은 합타입과 곱타입으로 분해됩니다.
C# 7에 튜플이 1급으로 취급되고 C# 8 부터 스위치식이 도입되고 개선되면서 곱타입을 다루는 데 언어적으로 성숙해 졌지요. 다만 합타입을 추가하지 못하는 바람에 ADT를 1급으로 다룰 수 없는 문제가 있습니다.
DU(Discriminated Unions)은 함수형 언어(Scala, haskell, f#)와 최근 개발 언어(Rust, Kotlin)에서 1급으로 제공하는 합타입으로 상속과 비슷해 보이지만 가장 큰 차이점은 상속에 대해 닫혀 있다는 점이지요. FSM(유한상태기계)를 언어에서 1급으로 다룰 수 있다는 장점도 있습니다.
C#이 더욱 저변을 넓힐 수 있는 기회라 생각되네요. (물론 한국 제외)
9개의 좋아요
# C# Language Design Meeting for June 25th, 2025
## Agenda
- [Unions](#unions)
- [Stand-alone issues](#stand-alone-issues)
- [Mutually exclusive issues](#mutually-exclusive-issues)
## Quote of the Day
- "Runtime typo unions"
## Discussion
### Unions
Champion issue(s):
* Closed enums: https://github.com/dotnet/csharplang/issues/9011
* Nominal type unions: https://github.com/dotnet/csharplang/issues/9411
Documents:
This file has been truncated. show original
1년 만에 최근 근황을 살펴 보니 앞으로 10년도 표준 문제로 다툴 기세군요.
5개 제안중 2개는 서로 완전 다른 이야기
2개의 좋아요
rkttu
7월 30, 2025, 3:34오전
3
사족입니다만 LDM 미팅이 2013년부터 시작해서 벌써 12년차에 들어가는군요. ㄷㄷ
2개의 좋아요
합 타입은 코드로 구현이 가능한 부분이고, 실제로 패키지가 있기도 해서, 개인적으로 그렇게 급한 문제는 아닌 것 같습니다.
당장은 Collection Expression 의 기본 타입이나 얼른 확정해줬으면 하는 바램이 더 큽니다.
var collection = [1, 2, 3, 4]; // error
List 가 될 것이라고 그러더니, 아직까지 감감 무소식이네요.
7개의 좋아요