Hacker News new | ask | show | jobs
by ccktlmazeltov 2188 days ago
I don't think you would need user generics for this to work.
2 comments

Without generics, sum types would have to be a built-in like maps and arrays.

With generics, discriminated unions can take on all sorts of user-defined shapes.

Without generics, structs can take on all sorts of user-defined shapes. It's just that the types of its fields are fixed at declaration.

Without generics but with sum types, the sum types can still take on all sorts of user-defined shapes. It's just that the types of its various alternatives are fixed at declaration.

Non-generic sum types are useful but you can’t build an option or result type out of them, so the usefulness is somewhat hampered.
But you don't need to, generic Option and Result types could be built as part of the standard library.
Yes but then you need neither sum types nor user-defined generics, you can just build-in whatever sugar is useful or necessary (possibly repurposing existing sugar e.g. the `select` statement).
sum types are still super useful imo without generics.