3 ms·
To be fair, enums represent a different and incompatible concept in every language I know. It's possible to support everybody's needs in a single language, but
by o11c 1y ago
To be fair, enums represent a different and incompatible concept in every language I know.
It's possible to support everybody's needs in a single language, but I'm not aware of any language that has done it yet.
- 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.
- za3faran 1y agoHave you tried them in Java?
- protolyticmind 1y agoRust has IMHO the best implementation of enums ... Mixed with match it is super powerful
- aldanor 1y agoDon't forget, Rust was first implemented in OCaml, you can guess where those best enums come from.
- sureglymop 1y agoKotlins enum classes are quite similar, probably even inspired by rust or prior ML languages. And there's `when` as an alternative to match. Kotlins syntax is in general a bit underrated imo and I disagree that Java is up to par.