-
Notifications
You must be signed in to change notification settings - Fork 12
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
Comments
@Frizi Do you have a particular idea of implement it in TypeScript? |
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). |
Maybe it can be done with https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/ |
(An idea💡)
The idea is to create Vectors and operator with types, e.g.
Vector<[x, y, pol, dir]>
or operatorOperator<[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?
The text was updated successfully, but these errors were encountered: