Remix.run Logo
toxik 5 days ago

I was so disappointed that this turned from Python to Haskell, I would just _love_ to have something like this in Python. Even just type annotations.

A similar thing I have been thinking about doing in robotics contexts is to annotate vectors and transformation matrices with their reference frames. So you can only matrix-vector multiply between compatible types: `object_in_world = camera_to_world @ object_in_camera`. It can be done somewhat in C++.

cosmic_quanta 5 days ago | parent | next [-]

Something I briefly mention in the post is pint [0] for Python, but unfortunately, I don't think dimensions can be specified via type annotations.

At least you can check the input of functions at runtime [1].

[0]: https://github.com/hgrecco/pint

[1]: https://pint.readthedocs.io/en/stable/advanced/wrapping.html

kardos 5 days ago | parent | prev | next [-]

Could this be done with an IDE plugin (for Pycharm or whatnot)? It is tedious to go though code and carefully annotate each variable and run so many compile test, read error, revise, cycles. It should be possible on a per function basis to statically check how each variable relates to the inputs and outputs, and just annotate those. Then the plugin could solve the units for each item, and only ask for an annotation where needed to resolve an ambiguous case.

ttshaw1 4 days ago | parent | prev [-]

Check out sympy.physics.units. I've been using it for unit-checking in my symbolic work for a few years.

https://docs.sympy.org/latest/modules/physics/units/index.ht...