Sum Types in Languages

Comments focus on sum types (algebraic data types like unions, enums, or discriminated unions), their advantages, implementations in languages such as Rust, Haskell, and TypeScript, and debates over their absence or equivalents in other languages.

📉 Falling 0.4x Programming Languages
3,148
Comments
19
Years Active
5
Top Authors
#7937
Topic ID

Activity Over Time

2008
1
2009
6
2010
4
2011
20
2012
34
2013
54
2014
125
2015
99
2016
111
2017
196
2018
201
2019
201
2020
292
2021
348
2022
306
2023
428
2024
410
2025
292
2026
20

Keywords

u.foo LoggedIn TypeScript monads.html ML MyUnion IIUC okmij.org GADT u.bar sum types sum types type unions haskell enum union languages scala

Sample Comments

cryptonector • Aug 14, 2023 • View on HN

You want "sum types", aka "algebraic types".

atroche • Oct 20, 2019 • View on HN

Do you mean sum types? Like Haskell's Maybe and Rust's Result?

karavelov • Dec 5, 2020 • View on HN

No support for sum types? I didn't see even simple unions covered.

auggierose • Mar 8, 2021 • View on HN

That's what sum types are for.

wereHamster • Apr 16, 2022 • View on HN

Congrats, you've re-invented sumtypes!

TazeTSchnitzel • Feb 25, 2021 • View on HN

Sum types are simpler, and harder to misuse, than the common alternatives (unions or dynamic typing).

freeone3000 • Nov 5, 2024 • View on HN

Languages with sum types, like Haskell and Rust, make these things trivial.

monkeyelite • Sep 30, 2025 • View on HN

How do you think sum types are implemented in functional languages?

endorphine • Mar 14, 2023 • View on HN

Can someone elaborate on what sum types are and an example in Rust?

seanclayton • Apr 26, 2021 • View on HN

Typescript provided none of those besides sum types.