|
|
|
|
|
by kvb
4368 days ago
|
|
No, not at all. It is true that units are erased at runtime, but the compile time behavior is quite sophisticated, going well beyond anything that's possible in C# or OCaml. (Your link is quite interesting, but I think that using a custom build step is "cheating" to some degree in that you can add arbitrary features by adding language-external post build processing). By being built into the language, units of measure in F# work naturally with type inference (and definitions can be measure-generic), so: let weirdOperation (x:float<_>) (y:float<_>) = x * x + y * y * y
will be inferred to have type x:float<'u ^ 3> -> y:float<'u ^ 2> -> float<'u ^ 6>
|
|
I guess, but: source code is still standard C#, it gives you pre-runtime static verification. As far as I understand Roslyn will support this kind of extensibility in a straightforward way. It is still better than unit testing same stuff in my opinion (except for specifying units in comments).
"By being built into the language" - do you mean F# code that uses units of measure wouldn't compile to OCAML (I am talking about simple compilability rather than proper support)?