Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Avoid recomputation when handling let patterns #167

Open
jmackie opened this issue Jan 7, 2023 · 0 comments
Open

Avoid recomputation when handling let patterns #167

jmackie opened this issue Jan 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jmackie
Copy link
Member

jmackie commented Jan 7, 2023

Need to do something similar to #114 only for let bindings.

For example:

module Example exports (..);


type T = T(Int);

some_expensive_function = fn (i) -> T(i);

fixme =
    let
        T(i) = some_expensive_function(5000);
    in
    i;

Generates:

function T($0) {
  return ["T", $0];
}
function some_expensive_function(i) {
  return T(i);
}
const fixme = (() => {
  if (some_expensive_function(5000)[0] === "T") {
    const i = some_expensive_function(5000)[1];  // ISSUE: some_expensive_function called again!
    return i;
  }
  throw new Error("Pattern match error");
})();
export { fixme, some_expensive_function, T };
@jmackie jmackie added the enhancement New feature or request label Jan 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant