Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
paavohtl
on Aug 31, 2020
|
parent
|
context
|
favorite
| on:
Sum Types in Julia and Rust
It is possible (and popular) to have sum types in TypeScript by manually adding a tag, though.
type Maybe<T> = | { kind: "Some", value: T } | { kind: "None" }
carlmr
on Aug 31, 2020
|
next
[–]
This is also why sum types are often referred to as tagged unions. They are a special case of a union, in Rust's case with support from the type system.
a_humean
on Aug 31, 2020
|
prev
[–]
Yep, Typescript's control flow analysis, type literals, and union types allow us have tagged unions/sum types. Probably its best feature.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: