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

Dimensions checked as types #33

Open
stared opened this issue Aug 24, 2020 · 3 comments
Open

Dimensions checked as types #33

stared opened this issue Aug 24, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@stared
Copy link
Collaborator

stared commented Aug 24, 2020

(An idea💡)

The idea is to create Vectors and operator with types, e.g.

Vector<[x, y, pol, dir]> or operator Operator<[spin, spin], [spin, spin]>

Thay way, it would be possible to check types at the TypeScript level. It seems that in plain TS the operations are clunky, but it is possible to use:

https://github.com/ksxnodemodules/typescript-tuple/

I didn't know how to approach it, as some operations (e.g. partialDot) make the type dependent on values.

Also, for dimensions - should be also incorporate basis?

@stared stared added the enhancement New feature or request label Aug 24, 2020
@Frizi Frizi closed this as completed Sep 7, 2020
@Frizi Frizi reopened this Sep 7, 2020
@stared
Copy link
Collaborator Author

stared commented Sep 13, 2020

@Frizi Do you have a particular idea of implement it in TypeScript?

@Frizi
Copy link
Contributor

Frizi commented Sep 14, 2020

I think it's possible and we could try doing something, but with typescript there are a few problems. First of all, typescript's loose variance rules and structural typing will make it tricky to guarantee that different generic dimensions won't be unified with each other by accident. Second, type-level operations can't really influence runtime. There is no code generated AT ALL from type-level generics. That means no type-aware compile time optimizations. The best we can wish for is a required value of generic type that user must provide, so we at least have something to play with, and all the real work will have to happen at runtime anyway (except maybe some equality checks that are hopefully redundant thanks to stronger types).

For performance alone though, we have a few other tricks in the bag as well. One would be to "tag" dimensions with symbol values and freeze them, so we have something unique to quickly compare against and there is no room for accidental mutation.

If we ever go with Rust here, there is much bigger potential for optimizations, as long as the dimensions would be specified on the Rust side as well (FFI boundary can't be generic).

@stared
Copy link
Collaborator Author

stared commented Nov 20, 2020

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
None yet
Development

No branches or pull requests

2 participants