Wanted: proper enum type and switch statement with pattern matching on enumerable types

Steven_Sagaert
Wed, 03 Aug 2022 12:23:05 +0000
Internals & Design

I’ve returned to Julia development after a break of a couple of years and I was suprised that there still not a proper enum type or a switch (or match if you like Scala) statement.

The current enum with @enum is not good enough. Because the value names are not qualified/scoped with the type name it’s easy to get a name clash with variables,parameters, other enum values especially if you’re refactoring existing code and introducing enums. I’ve run into this myself. I’d like enum to be more like java enum where you say Type.value for a enum value (unless in some like a with statement where you then can leave of the Type)

I’d also like to see a switch/match statement for use with enums and more generally enumerable types like int, strings instead of long if/elseif/else chains. That would definitely cleanup some code that I have.
Ideally the switch could be made more powerful with pattern matching like in Haskell or Scala. Even languages like Java/C# are introducing this now (or have done it). But I’d would already be happy with the basic case

6 posts - 5 participants