tag:blogger.com,1999:blog-8383004232931899216.post3888711767520328162..comments2023-11-01T11:47:57.046-04:00Comments on Designing ParaSail, a new programming language: Physical Units in ParaSailTucker Tafthttp://www.blogger.com/profile/08866496974237052847noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8383004232931899216.post-27045274065170808952022-06-29T01:22:33.571-04:002022-06-29T01:22:33.571-04:00Good point. In some cases, units are not enough. ...Good point. In some cases, units are not enough. You would need to add some additional semantics. Be that as it may, units by themselves can provide a useful "consistency check" on a computation, even if they don't embody all of the semantics that are possible.<br /><br />Most programming languages don't support units, much less the additional semantics you are suggesting. The late John Knight, UVA professor, talked about "real-world" types, which I think begins to include some of the kinds of semantics you mention. Here is a paper of his from 2015: https://www.researchgate.net/publication/300254678_Real-World_Types_and_Their_Application Tucker Tafthttps://www.blogger.com/profile/08866496974237052847noreply@blogger.comtag:blogger.com,1999:blog-8383004232931899216.post-34627149109514366302022-06-28T23:26:57.812-04:002022-06-28T23:26:57.812-04:00The difficulty with this design of quantities is t...The difficulty with this design of quantities is that you can add up things that don't work. For example, length + width + height is type-correct but not meaningful, except that the limit on the size of FedEx packages is set that way. A stronger example is adding energy and torque, which are both newton * meters.John Cowanhttps://www.blogger.com/profile/03866951247699187535noreply@blogger.comtag:blogger.com,1999:blog-8383004232931899216.post-21641198618797891502010-02-18T12:52:22.378-05:002010-02-18T12:52:22.378-05:00The model here is that one unit for a given kind o...The model here is that one unit for a given kind of physical quantity (e.g. "m") is the primary unit, and the others are defined in terms of it using a Scale factor (e.g. "cm" has 0.01 Scale). Which kind of physical quantity a type represents is determined by the values in the Unit_Dimensions array. The primary units should be set up so they are related to one another using Scale factors of 1.0, so no scaling is needed as part of multiplication for the primary units (e.g. "m", "kg", "s", "N", "J", etc.). <br /><br /> The SI system need not be used. Any system, such as CGS, which has the same scale of 1.0 connecting the different units, would work with the given scheme (e.g. "cm", "g", "s", "dyn", "erg", etc.).<br /><br />As far as equivalence, for instances of a generic interface, it is based on having the same actual interface parameters. If we supported multiplication by having a separate interface which provided the "*" operator and took two type parameters, we would need a special case to say that the interface defines only "commutative" operators, and so Multiplying<A,B> is considered equivalent to Multiplying<B,A>. <br /><br /> We avoid this equivalence issue in the above approach because we don't have a separate interface to instantiate to get multiplying operators. Instead, the multiplying operators themselves are "generic" and instantiated implicitly as needed to match the context where the operator is used.Tucker Tafthttps://www.blogger.com/profile/08866496974237052847noreply@blogger.comtag:blogger.com,1999:blog-8383004232931899216.post-75798600246383611152010-02-18T12:08:38.653-05:002010-02-18T12:08:38.653-05:00How about inheritance for units of measurement? C...How about inheritance for units of measurement? Could a function take a distance argument and be able to compute a value for anything that inheirts from a distance unit (m, ft., rods, etc.) Or are you purposefully sticking to SI units? To me it seems that would cut out certain applications in domains with specialized units. <br /><br />Could you elaborate on why the units resulting from 8m * 1sec = 8 m*sec and 1sec * 8m = 8 sec*m wouldn't be trivial to equate? Maybe I am misunderstanding the part about worrying about extra, equivalent compound units, though...jagwiohttps://www.blogger.com/profile/07234976924523283472noreply@blogger.com