The first code is indeed brittle, in the sense that it translates three definite cases as two cases and everything else, which is semantically very different.
What you achieve manually with the fourth case is what the Elm compiler does automatically with a pattern matching on an algebraic data type:
With this code, you have your never case for free. If someone adds a type constructor in TrafficLight, respondToTrafficLight won't compile anymore. Elm functions must be total functions.
The first code is indeed brittle, in the sense that it translates three definite cases as two cases and everything else, which is semantically very different.
What you achieve manually with the fourth case is what the Elm compiler does automatically with a pattern matching on an algebraic data type:
With this code, you have your
never
case for free. If someone adds a type constructor inTrafficLight
,respondToTrafficLight
won't compile anymore. Elm functions must be total functions.Oh yea I would love to use Elm! I asked my coworkers to check it out and they almost unanimously said no. :(