3 ms·
Seems like it kinda has Sum Types, so Nim passes the litmus test for respectable static type-system in this day and age. https://nim-lang.org/docs/manual.html#
by frou_dh 3y ago
Seems like it kinda has Sum Types, so Nim passes the litmus test for respectable static type-system in this day and age.
https://nim-lang.org/docs/manual.html#types-object-variants https://nim-lang.org/docs/manual.html#types-object-variants
- jackmott42 3y agoI feel the same way as you! I've seen many language ideas come and go in my career and sum types are one I feel now should be a basic requirement. I miss them in any language without them.
- c-cube 3y agoWhen I looked at it a few years ago, the compiler didn't prevent you from accessing fields from the wrong variant, and didn't provide exhaustivity checks. So I think it still falls short of this (excellent) litmus test :/
- cobby 3y agoAlso Nim requires you to use unique field names across all variants.
- alwaysbeconsing 3y agoThis annoying restriction is lifted in Nim 2; see the linked announcement.
- xigoi 3y agoWhere in the announcement does it say that?
- ElegantBeef 3y agoThey likely read "overloadable enums" and went "Oh Rust calls their tagged unions enums" so assumed all languages did.
- alwaysbeconsing 3y agoOh, no, I actually misunderstood cobby's complaint: the field names, yes, those still have to be unique. Which is also a bit annoying, though I've seen discussions about changing it.
- elcritch 3y agoThey've improved the compiler analysis for them significantly, including exhaustivity checks and field checks.