4 ms·
Worth noting that F# has language-support for Units of Measures and countless new languages have come since 2008 without that in mind.
by davidgrenier 12y ago
Worth noting that F# has language-support for Units of Measures and countless new languages have come since 2008 without that in mind.
- Osmium 12y ago> Worth noting that F# has language-support for Units of Measures I had no idea. That is crazy cool. Do you have any recommended resources for learning how this works behind the scenes? (I tried implementing something similar in Swift, without knowledge of prior examples, so probably ended up doing it in a really dumb way. I tried using structs ('Quantities') containing the underlying value and also dimensional information, and then enabling mathematical operations using operator overloading and generics. I'd love to know of a better/"proper" way of implementing it though. The big unknown for me was the best underlying type/data structure to use to represent SI dimensions, including fractional dimensions, and that would allow them to be combined algebraically. Might just have to have another go this weekend following F#'s example!) Edit: found this paper if anyone's interested http://research.microsoft.com/en-us/um/people/akenn/units/CEFP09TypesForUnitsOfMeasure.pdf http://research.microsoft.com/en-us/um/people/akenn/units/CE...
- doublec 12y ago"Scientific and Engineering C++" by Barton and Nackman had a good example of doing units in C++ using templates. This blog post describes the basic approach http://learningcppisfun.blogspot.com/2007/01/units-and-dimensions-with-c-templates.html http://learningcppisfun.blogspot.com/2007/01/units-and-dimen...
- louthy 12y ago> I had no idea. That is crazy cool. Do you have any recommended resources for learning how this works behind the scenes? http://fsharpforfunandprofit.com/posts/units-of-measure/ http://fsharpforfunandprofit.com/posts/units-of-measure/ The units are lost at runtime and are used for static type checking only. So if you were to consume an F# lib from C# (for example) then you wouldn't have a such strong system. Hopefully one day they'll end up as part of the CLR so it can be enforced at runtime too.
- pron 12y agoAdded in Java 8 as one of its pluggable type systems: http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#units-checker http://types.cs.washington.edu/checker-framework/current/che...
- bokchoi 12y agoOk, that's awesome.