
F# Units of Measure – A Worked Example - numo16
http://stevenpemberton.net/blog/2015/03/11/FSharp-Units-Of-Measure/
======
RobotCaleb
This is neat stuff, and I've looked into it before. One question I have,
though, is regarding interoperability with C#. If I have a units library that
is in F# using what's shown in OP, would I be able to use the UoM in C#, or
would I have to revert to unitless values on the C# side of the interface?

~~~
ghuntley
From the article @ "Units of Measure at runtime and interoperability ":

One key point to take heed of, is that units of measure do not exist at
runtime. They are intended for static type checking only and therefore prevent
us implementing functionality based on checking units.

They are also not part of the wider .NET type system and can therefore not be
consumed, or used, by any non F# assembly. If exposing units of measure to
consumers, the units are simply not visible and all values will be treated as
there underlying, dimensionless type.

~~~
M8
Yes, that's the biggest problem with them.

------
bsaul
I could easily imagine a language extension that would automatically create
"companion" number types for any other type ( you create a type "animal" and
you automically get a "number of animals" unit of measure type.

This way you would almost never have "raw" int or float types.

~~~
andrewchambers
I'm pretty sure type providers can do that.

------
jug
F# is perfect for a part of our application, I just dislike that we can't mix
.NET languages within the same Visual Studio project without going through
hoops. I had expected this to have been solved by now since they all compile
down to IL anyway.

Hmm, maybe we'll just have to put it in a separate project even if it feels
silly to just have a few classes there, which in turn are strongly related to
others. It just feels so perfect for these particular classes.

------
jamez1
Every language should have this. Simple idea but it makes so much sense.

