Skip to content

Handle struct types more conveniently #103

@samestep

Description

@samestep

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.

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