> > I generally don't like using equality test on union types because that > makes your code more prone to errors - later on you might decide to add / > remove some types from union type.
I'm on board with that. I try to avoid catch-all underscores in case statements for the same reason. But if your case statement is really as redundant as the ones in your examples, I think these are both options worth considering (as is refactoring -- as Wouter suggested -- which is often the best decision). How is this handled in other languages like OCaml or Haskell? Haskell does not allow this either. (At least it didn't 5 years ago, when this proposal <https://wiki.haskell.org/MultiCase> was made). The difference is, the formatting conventions for Haskell are much more compact. But in Elm, its perfectly valid to compress your case statement into this: case someTypeValue of A -> stuff1 B _ -> stuff2 C _ _ -> stuff2 D _ _ _ -> stuff2 On Fri, Dec 9, 2016 at 8:08 AM, Petr Huřťák <[email protected]> wrote: > I generally don't like using equality test on union types because that > makes your code more prone to errors - later on you might decide to add / > remove some types from union type. > > On Friday, December 9, 2016 at 4:57:48 PM UTC+1, Nick H wrote: >> >> You can also do equality tests on type values, which means in your first >> two cases you can use an if statement. >> >> if someValue == A then >> stuff1 >> else >> stuff2 >> >> This only works if your type values aren't storing any data. >> >> On Fri, Dec 9, 2016 at 7:25 AM, Petr Huřťák <[email protected]> wrote: >> >>> Hi, >>> >>> I would like hear some discussion on grouping of branches in `case of` >>> statement . Currently it is not possible to use one branch for multiple >>> conditions. >>> >>> Something along these lines: >>> >>> case someTypeValue of >>> A -> >>> -- code >>> >>> B -> >>> C -> >>> D -> >>> -- different code >>> >>> >>> Current alternative is this >>> >>> case someTypeValue of >>> let >>> stuff2 = >>> -- code >>> in >>> A -> >>> -- different code >>> >>> B -> >>> stuff2 >>> >>> C -> >>> stuff2 >>> >>> D -> >>> stuff2 >>> >>> >>> Which is unnecessarily verbose and harder to read. >>> >>> One question is how this would work when there in cases where matched >>> patterns have some values attached to them >>> >>> case someTypeValue of >>> A -> >>> -- stuff1 >>> >>> >>> B _ -> >>> C _ _ -> >>> D _ _ _ -> >>> -- stuff2 >>> >>> How is this handled in other languages like OCaml or Haskell? >>> >>> NOTE: moved from https://groups.google.com/forum/#!topic/elm-dev/DtUT2ie >>> YTDo >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Elm Discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
