rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Match on variant spread in switch

Open jacobp100 opened this issue 7 months ago • 1 comments

Since the new ReScript allows spreading variants in the definitions, should we also be able to match them like polymorphic variants?

Polymorphic variants
type ex1A = [#X | #Y]
type ex1B = [#Z]
type ex1 = [ex1A | ex1B]

let ex1 = (x: ex1) =>
  switch x {
  | #...ex1A => "A"
  | #...ex1B => "B"
  }
Variants with spread
type ex2A = X | Y
type ex2B = Z
type ex2 = | ...ex2A | ...ex2B

let ex2 = (x: ex2) =>
  switch x {
  | _ => "???"
  }

jacobp100 avatar Jan 12 '24 18:01 jacobp100

It'd definitely be great. Related: https://github.com/rescript-lang/rescript-compiler/discussions/6273#discussioncomment-6645282

zth avatar Jan 12 '24 18:01 zth