mita
mita copied to clipboard
RFC: add switch case to language
@andreasmuelder: for implementing a statemachine in the program DSL it is much more readable to have a switch case instead of if else if blocks. We should add a switch case to the language (maybe without fall through)
Sum types already have all required functionality for switching on enums. The only thing missing is switching on value types. For state machines you should always use named states (enums) and never just integers.
If we only want to allow switching on enums, we could add switch statements without modifying the statement generator by re-using the sum types: the parser just returns the equivalent sum type objects.
switch <--> where
case <--> is
default <--> isother
enum <--> alt
enumMember <--> singleton
@32leaves
I hope that in Mita the need to express a statemachine using enums and switch (still far better than integer and switch) will be minimal. Ideally users never have to model a statemachine explicitly themselves. @swegendt's work is in that direction.
Personally I don't see the need for (value) switch case considering their often troubled syntax (C, Java). Other than full-blown pattern matching (think Scala) or for sum types I'm not sure we need that right now. That said, others might well disagree :)