Skip to content

We could be optimising ADT pattern matching more #4924

@jacobp100

Description

@jacobp100

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
    • Ideally in OCaml syntax for now. To isolate the problem caused by either Reason or the New Syntax.
  • OS and browser versions, if relevant.
  • Is it already fixed in master?

Take an ADT with a mix of cases with and without arguments.

type test =
  | NoArg
  | AnotherNoArg
  | OtherArg(int)

let test = x =>
  switch x {
  | NoArg => true
  | _ => false
  }

The JS output is,

function test(x) {
  if (typeof x === "number") {
    return x === 0;
  } else {
    return false;
  }
}

For this, the output could easily be input === 0.

This wouldn't be an issue if a minifier could optimise this - but even GCC advanced cannot do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions