Opened 4 years ago

Last modified 22 months ago

#8927 new feature request

Multiple case match at once

Reported by: vxanica Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 7.8.1-rc2
Keywords: case, multiple Cc: vxanicauk@…, gkaracha
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #3919 Differential Rev(s):
Wiki Page:

Description

In F# we can do

match x with 
    | 1 | 2 | 3 -> "123"
    | 4 | 5 | 6 -> "456"

It will be nice if we have an extension which allows us to do

case x of
     1 | 2 | 3 -> "123"
     4 | 5 | 6 -> "456"

Change History (7)

comment:1 Changed 4 years ago by vxanica

Cc: vxanicauk@… added
Version: 7.6.37.8.1-rc2

comment:2 Changed 4 years ago by Fuuzetsu

What happens in the case like

case x of
     Just y | Nothing -> y

While I think it'd be nice to have, the utility seems limited to constructors without arguments.

Would this work?

data Foo = A Int | B Int | C String

case x of
     A y | B y = "AB" ++ show y
     C y -> y

and would this work?

data Foo = A Int | B () | C Double

case x of
     A y | B y | C y = show y

comment:3 in reply to:  description Changed 4 years ago by hvr

Replying to vxanica:

case x of
    1 | 2 | 3 -> "123"
    4 | 5 | 6 -> "456"

btw, this concrete syntax would collide with Haskell2010's Pattern Guards

More specifcally, what would

case x of
    False | True -> "123"

mean?

Last edited 4 years ago by hvr (previous) (diff)

comment:4 Changed 4 years ago by schyler

Why not swap out | with , ?

comment:5 Changed 4 years ago by nomeata

difficulty: Easy (less than 1 hour)Unknown

comment:6 Changed 22 months ago by gkaracha

Cc: gkaracha added

comment:7 Changed 22 months ago by rwbarton

I like the idea of disambiguating or-patterns and guards with parentheses, since I expect to be able to use or-patterns compositionally (nested within a larger pattern) anyways. So for hvr's last example

case x of
  (False | True) -> "123"

Don't know if this would cause major problems in the parser.

Note: See TracTickets for help on using tickets.