Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
Kostarrr
· 4y ago · 0 comments
Actually, go generics can do sum types, it’s just not well known or advertised.
Comments
[–]
tsimionescu
4y ago
No, they can't. Or more precisely, only generic type parameters can be sum types, not actual runtime variables/parameters/return types/struct fields.
[–]
chombier
4y ago
> not actual runtime variables/parameters/return types/struct fields.
Is it possible to church-encode these with Go generics?
[–]
tsimionescu
4y ago
Yes, probably, but I'm not sure that would be very ergonomic (I don't think you'd want to use it for something like Optional), if I understand correctly how it would work.