mita icon indicating copy to clipboard operation
mita copied to clipboard

RFC: add switch case to language

Open wegendt-bosch opened this issue 6 years ago • 2 comments

@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)

wegendt-bosch avatar Apr 25 '18 14:04 wegendt-bosch

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

wegendt-bosch avatar Apr 25 '18 14:04 wegendt-bosch

@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 :)

wegendt-bosch avatar Apr 25 '18 14:04 wegendt-bosch