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

Handle struct types more conveniently #103

Open
samestep opened this issue Sep 18, 2023 · 0 comments
Open

Handle struct types more conveniently #103

samestep opened this issue Sep 18, 2023 · 0 comments

Comments

@samestep
Copy link
Contributor

samestep commented Sep 18, 2023

Consider this example:

import { Real, Vec, fn, vec } from "rose";

const foo = fn([Real, Real], Real, (x, y) => {
  const z = f(x, y);
  const w = g(x, z);
  const u = h(z);
  const v = α(w, u);
  return v;
});

const bar = fn(
  [Vec(n, { x: Real, y: Real })],
  Vec(n, Real),
  (vals) => vec(n, Real, (i) => {
    const { x, y } = vals[i];
    return f(x, y);
  })
);

The x and y variables inside the body of the vec both get typed as symbol, when they should be typed as Real, causing this error in the call to f:

Argument of type 'symbol' is not assignable to parameter of type 'Real'.

If you add an as const after the { x: Real, y: Real } type, the correct behavior occurs, but this is ugly. There should be a way to handle these sorts of types without the user having to write as const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant