3 ms·
"enums represent a different and incompatible concept in every language I know." Enums has always felt very natural in every modern languages i've tried (swift
by bsaul 1y ago
"enums represent a different and incompatible concept in every language I know."
Enums has always felt very natural in every modern languages i've tried (swift and rust, for example), even with associated values. The underlying "sum type" concept also is very intuitive, and seems very complementary to structs for example.
Can you expand a bit on what you mean ?
- __s 1y agoSum types are cool. Many languages implement enums which are not tagged union sum types (even when language has rich sum types) https://en.cppreference.com/w/c/language/enum https://en.cppreference.com/w/c/language/enum https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/enums https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... https://docs.python.org/3/library/enum.html https://docs.python.org/3/library/enum.html https://api.rubyonrails.org/v5.2.4.5/classes/ActiveRecord/Enum.html https://api.rubyonrails.org/v5.2.4.5/classes/ActiveRecord/En... https://sorbet.org/docs/tenum https://sorbet.org/docs/tenum https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html https://docs.oracle.com/javase/tutorial/java/javaOO/enum.htm... https://dart.dev/language/enums https://dart.dev/language/enums https://www.postgresql.org/docs/current/datatype-enum.html https://www.postgresql.org/docs/current/datatype-enum.html https://dev.mysql.com/doc/refman/8.4/en/enum.html https://dev.mysql.com/doc/refman/8.4/en/enum.html https://zig.guide/language-basics/enums https://zig.guide/language-basics/enums https://www.erlang.org/eeps/eep-0013 https://www.erlang.org/eeps/eep-0013 https://hackage.haskell.org/package/planet-mitchell-0.1.0/docs/Enum.html https://hackage.haskell.org/package/planet-mitchell-0.1.0/do... https://www.ibm.com/docs/en/openxl-fortran-aix/17.1.1?topic=attributes-enumend-enum-fortran-2003 https://www.ibm.com/docs/en/openxl-fortran-aix/17.1.1?topic=...
- willtemperley 1y agoThis. I find Swift and Rust enums, which are indeed very similar, to be incredibly good at modelling the real world. For example the standard geospatial vector types which are heterogeneous and even recursive in the case of GeometryCollections can be modelled and operated upon very cleanly.