Type checking for units #3309
michaeldickens
started this conversation in
Squiggle Improvement Proposal
Replies: 1 comment
-
Yep, we've discussed this a bit. I think it could be neat, especially, on my end, for things like variable presentation in the UI. There are probably some minimal ways of doing this, and some much harder ways. My guess is that it will take some thinking to figure out the best approach. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think it would be useful if Squiggle could let you declare units and then do type checking on the units. I recently wrote a Squiggle model that had a lot of type conversions, for example calculating the profit of a farm using the cost of materials per acre per season and the revenue per kilogram. Combining these two requires doing a lot of unit conversions.
I would like to be able to declare arbitrary units for my variables and have Squiggle type-check them, for example:
would produce something like
Oops, I divided the variables when I should have multiplied!
It could also support type inference—if you don't declare a type, it will infer the type and show it to you alongside the distribution when you click on a variable.
I think a type system like this would be doable and would catch a lot of errors in more complex models.
This idea overlaps with Ozzie's annotated fields proposal, but it's more lightweight, and perhaps harder to implement. I can broadly visualize how it could be done but I don't know the specifics of Squiggle internals.
Beta Was this translation helpful? Give feedback.
All reactions