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

Generic structs #452

Open
sharkdp opened this issue Jun 4, 2024 · 4 comments
Open

Generic structs #452

sharkdp opened this issue Jun 4, 2024 · 4 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Jun 4, 2024

With the recent changes to generics in #443, it might not be too hard to support generic structs. As in:

struct Pair<A, B> {
  first: A,
  second: B,
}

or maybe

struct Vec<D> {
  x: D,
  y: D,
  z: D,
}
@sharkdp
Copy link
Owner Author

sharkdp commented Jul 24, 2024

For the implementation of this function, I wanted to have something like

struct MixedUnitComponent<D: Dim> {
  unit: D,
  name: String,
}

in order to pass just one List<MixedUnitComponent<D>> argument around instead of two synchronized lists List<D> and List<String>.

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 30, 2024

This would also be useful for the implementation of the plotting functionality, which currently falls back to Scalars using value_of. And the unit names are transported in the string arguments 🙄

struct _PlotData {
  x_label: String, # something like "length [m]"
  y_label: String,
  xs: List<Scalar>,
  ys: List<Scalar>,
}

It would be much nicer to be able to write

struct _PlotData<X: Dim, Y: Dim> {
  x_label: String, # only "length"; unit can be determined from `xs`
  y_label: String,
  xs: List<X>,
  ys: List<Y>,
}

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 30, 2024

Early draft: #514

This was referenced Aug 5, 2024
@sharkdp
Copy link
Owner Author

sharkdp commented Aug 10, 2024

Another example where this is needed: #529

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

No branches or pull requests

1 participant