An example of what it could look like.

In F#, you can group cases together which have the same parameter type

match x with
    | A i ->
        // stuff1

    | B s | C s | D s ->
        // stuff2 on s

However you cannot group together cases with different parameters types

match x with
    | A i | B s | C s | D s -> // error

However in F# multiple parameters to an ADT are tuples, and you can use 
underscore for the whole tuple.

On Friday, December 9, 2016 at 9:25:29 AM UTC-6, Petr Huřťák 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/DtUT2ieYTDo
>
>

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to