Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant