<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx</link><description>In today's article I'll show you how to use different systems of units, convert between units, and interface with non-unit-aware code. PowerPack goodies First, though, let's have a look at some handy definitions provided in the F# PowerPack. To access</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8920025</link><pubDate>Tue, 02 Sep 2008 16:59:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920025</guid><dc:creator>alexey_r</dc:creator><description>&lt;p&gt;A great feature!&lt;/p&gt;
&lt;p&gt;How do unitful quantities look to the CLR? Something like&lt;/p&gt;
&lt;p&gt;[Measure]&lt;/p&gt;
&lt;p&gt;struct Second : IMeasure {}&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;[Measure]&lt;/p&gt;
&lt;p&gt;struct Mult&amp;lt;M1,M2&amp;gt; : IMeasure where M1 : IMeasure where M2 : IMeasure {}&lt;/p&gt;
&lt;p&gt;?&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8920486</link><pubDate>Tue, 02 Sep 2008 22:00:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920486</guid><dc:creator>wil2200</dc:creator><description>&lt;p&gt;Great post. However, I am having issues running the &amp;quot;gravitionalForce&amp;quot; portion of it. &lt;/p&gt;
&lt;p&gt;I keep getting an error saying that &amp;quot;error FS0039: The namespace or module 'SI' is not defined.&amp;quot; even though I referenced it in both ways (I also have powerpack added to the project):&lt;/p&gt;
&lt;p&gt;open SI and/or&lt;/p&gt;
&lt;p&gt;open Microsoft.FSharp.Math.SI&lt;/p&gt;
&lt;p&gt;any thoughts on this?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;~sparky&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8920660</link><pubDate>Tue, 02 Sep 2008 23:26:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920660</guid><dc:creator>andrewkennedy</dc:creator><description>&lt;p&gt;alexey_r: &lt;/p&gt;
&lt;p&gt;Units actually don't get seen at all by the CLR - they are &amp;quot;erased&amp;quot;. They are a purely static phenomenon, which means that the performance of code with units is no worse than the performance of the code with the units removed. You can think of them as a &amp;quot;refinement&amp;quot; of usual .NET types, seen only by F#. Of course this has some downsides (no runtime inspection of units) but our experience so far has been that they are in any case extremely useful in practice. And interestingly, all the &amp;quot;classical&amp;quot; functional languages (Haskell, Caml, OCaml, Standard ML) have purely static type systems.&lt;/p&gt;
&lt;p&gt;sparky: did you include&lt;/p&gt;
&lt;p&gt;open Microsoft.FSharp.Math&lt;/p&gt;
&lt;p&gt;? This has PhysicalConstants as a submodule.&lt;/p&gt;
&lt;p&gt;- Andrew.&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8920869</link><pubDate>Wed, 03 Sep 2008 01:29:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920869</guid><dc:creator>WillSmith</dc:creator><description>&lt;p&gt;Would be nice to have unit of measure support as a general class library in the .net framework. &amp;nbsp;Can you specify the scale and precision as well?&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8921000</link><pubDate>Wed, 03 Sep 2008 03:04:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921000</guid><dc:creator>aatreya</dc:creator><description>&lt;p&gt;Andrew,&lt;/p&gt;
&lt;p&gt;How can I get the following to compile?:&lt;/p&gt;
&lt;p&gt;[&amp;lt;Measure&amp;gt;]&lt;/p&gt;
&lt;p&gt;type km =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static member toM = 1.0/1000.0&amp;lt;m/km&amp;gt;&lt;/p&gt;
&lt;p&gt;[&amp;lt;Measure&amp;gt;]&lt;/p&gt;
&lt;p&gt;type m =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static member toKm = 1000.0&amp;lt;km/m&amp;gt;&lt;/p&gt;
&lt;p&gt;Seems like there's a fundamental limitation I'm running up against... or hopefully I'm just missing something. &amp;nbsp;The definition of m requires the definition of km, and vice versa.&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8921020</link><pubDate>Wed, 03 Sep 2008 03:13:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921020</guid><dc:creator>andrewkennedy</dc:creator><description>&lt;p&gt;You can define mutually recursive measures using &amp;quot;and&amp;quot; to connect them and placing the Measure attribute immediately before the name of the measure:&lt;/p&gt;
&lt;p&gt;type [&amp;lt;Measure&amp;gt;] km = &lt;/p&gt;
&lt;p&gt; &amp;nbsp;static member toM = 1.0/1000.0&amp;lt;m/km&amp;gt;&lt;/p&gt;
&lt;p&gt;and [&amp;lt;Measure&amp;gt;] m =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;static member toKm = 1000.0&amp;lt;km/m&amp;gt;&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8921026</link><pubDate>Wed, 03 Sep 2008 03:24:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921026</guid><dc:creator>aatreya</dc:creator><description>&lt;p&gt;Wonderful - thanks! &amp;nbsp;I'm so excited that a practical programming language finally has units-of-measure capability. &amp;nbsp;Nice work.&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8921086</link><pubDate>Wed, 03 Sep 2008 04:38:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921086</guid><dc:creator>sparky00</dc:creator><description>&lt;p&gt;This is incredibly annoying.&lt;/p&gt;
&lt;p&gt;[1] Reference FSharp Powerpack.dll - check&lt;/p&gt;
&lt;p&gt;[2] open Microsoft.FSharp.Math - Alt+Enter -&amp;gt; FSI pass&lt;/p&gt;
&lt;p&gt;[3] open SI - Alt+Enter -&amp;gt; FSI FAIL [error FS0039: The namespace or module 'SI' is not defined.]&lt;/p&gt;
&lt;p&gt;doing something as simple as:&lt;/p&gt;
&lt;p&gt;#light&lt;/p&gt;
&lt;p&gt;open Microsoft.FSharp.Math&lt;/p&gt;
&lt;p&gt;open SI&lt;/p&gt;
&lt;p&gt;let distance (d:float&amp;lt;m&amp;gt;) = d &lt;/p&gt;
&lt;p&gt;does not work -&amp;gt; anyone else has this problem?&lt;/p&gt;
&lt;p&gt;The VS IntelliSense and the documentation says that the SI module is installed, yet when I open and try to use it, nothing works. &lt;/p&gt;
&lt;p&gt;It seems to me that the problem is with the FSI and interpreting namespaces/modules but if anyone can give me some insights, that will really help!&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8921410</link><pubDate>Wed, 03 Sep 2008 09:23:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921410</guid><dc:creator>int19h</dc:creator><description>&lt;p&gt;&amp;gt; As far as F# is concerned, ft and m have nothing to do with each other. It's up to you, the programmer, to define appropriate conversion factors. &lt;/p&gt;
&lt;p&gt;This is mildly annoying. There's no reason why feet cannot be converted to meters and back automatically (it's not a narrowing conversion, so no opportunity for data loss), and even less for not being able to convert between m and km. It would seem to me that boost::units approach, which differentiates between abstract measures (duration, distance etc), and specific units of measurement, is more convenient.&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8922063</link><pubDate>Wed, 03 Sep 2008 18:04:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8922063</guid><dc:creator>davidacoder</dc:creator><description>&lt;p&gt;This whole thing is seriously cool. Just today we stubmled again with unit mix up in our simulation code.&lt;/p&gt;
&lt;p&gt;But then, my most urgent question would be whether there are any plans to support this in other languages as well? F# is nice, but we have a large investment in C# and really wouldn't want to move to F# just for the unit stuff... Any ideas on that?&lt;/p&gt;
</description></item><item><title>FIXED: error FS0039: The namespace or module 'SI' is not defined.</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8922553</link><pubDate>Wed, 03 Sep 2008 22:24:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8922553</guid><dc:creator>sparky00</dc:creator><description>&lt;p&gt;I finally got this to work and I realized where the problem was. I was using the default F# project and .fs file to type up all the code in but when I Alt+Enter and send to FSI, that is where the problem started.&lt;/p&gt;
&lt;p&gt;Even though I added the reference via &amp;quot;Add Reference&amp;quot;, I still get the error because FSI is not aware of project settings and all that. So in addition, I had to do #r &amp;quot;FSharp.PowerPack.dll&amp;quot; in the FSI window first, then Alt+Enter the rest of the code to it. Works now.&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;
&lt;p&gt;~sparky&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8923766</link><pubDate>Thu, 04 Sep 2008 09:23:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8923766</guid><dc:creator>int19h</dc:creator><description>&lt;p&gt;It would seem to be that Microsoft is deliberately pushing for F# for scientific computing now, while C# is your typical &amp;quot;general-purpose&amp;quot; (read: system &amp;amp; LOB) language. C# 4.0 is expected to have 4 new language features, one of them generic variance - I wouldn't expect to see units among the other three. Nor anytime soon - DbC, for example, would probably be higher-priority for C#.&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8925365</link><pubDate>Fri, 05 Sep 2008 01:30:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8925365</guid><dc:creator>yemi</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt; One thing that I stumbled upon. The value conversion on the types get masked when you set a literal with the same name as a type. In FSI:&lt;/p&gt;
&lt;p&gt;[&amp;lt;Measure&amp;gt;] type km = static member pM = 1000.0&amp;lt;km/m&amp;gt;;;&lt;/p&gt;
&lt;p&gt;[&amp;lt;Measure&amp;gt;] type m = static member pK = 0.001&amp;lt;m/km&amp;gt;;;&lt;/p&gt;
&lt;p&gt;let km = 1.0&amp;lt;km&amp;gt;;;&lt;/p&gt;
&lt;p&gt;km;;&lt;/p&gt;
&lt;p&gt;m.pK;;&lt;/p&gt;
&lt;p&gt;km.pM;;&lt;/p&gt;
&lt;p&gt; The last line errors saying it can't find pM. Good day.&lt;/p&gt;
&lt;p&gt;Yemi Bedu&lt;/p&gt;
</description></item><item><title>re: Units of Measure in F#: Part Two, Unit Conversions</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8925900</link><pubDate>Fri, 05 Sep 2008 07:39:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8925900</guid><dc:creator>michen</dc:creator><description>&lt;p&gt;Does F# support units with different zero values, e.g. Kelvin and Celsius? What I mean is that conversion of 100C to K depends on whether 100C in this case means temperature of boiling water (then the result is 373.15K) or difference between boiling water temperature and freezing water temperature (in this case the answer is 100K).&lt;/p&gt;
&lt;p&gt;One can write two converters (say C.AbsToK and C.DeltaToK), but then it is user's responsibility to do it right - F# will do no checking.&lt;/p&gt;
&lt;p&gt;Or maybe one should define two types of K and C units - absolute and delta, with rules like AbsX-AbsX=DeltaX, AbsX+DeltaX=AbsX, AbsX+AbsX=illegal, and so on?&lt;/p&gt;
</description></item><item><title>Kelvin vs Celsius</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8926435</link><pubDate>Fri, 05 Sep 2008 18:38:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8926435</guid><dc:creator>andrewkennedy</dc:creator><description>&lt;p&gt;Good point regarding units with different zero values. The units supported by F# are those for which multiplication makes sense, and Celsius doesn't fit this model. It makes no sense to double an absolute temperature measured in degrees Celsius. Whereas for Kelvin, this is fine.&lt;/p&gt;
&lt;p&gt;A similar situation arises with absolute times versus time periods - it would indeed be nice to permit subtraction of absolute times, and rule out addition of absolute times, but permit either operation on time *periods*. One can do this by defining separate *types*, a little like DateTime and TimeSpan from the .NET framework.&lt;/p&gt;
</description></item><item><title>The Weekly Source Code 34 - The Rise of F#</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#8964791</link><pubDate>Thu, 25 Sep 2008 12:46:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8964791</guid><dc:creator>Readed By Wrocław NUG members</dc:creator><description>&lt;p&gt;First, let me remind you that in my new ongoing quest to read source code to be a better developer ,&lt;/p&gt;
</description></item><item><title>F#中有趣的计量单位</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#9156007</link><pubDate>Sat, 29 Nov 2008 15:23:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9156007</guid><dc:creator>Anders Cui</dc:creator><description>&lt;p&gt;NASA气象卫星意外坠落说明，计量单位绝非小事。为编程语言添加对计量单位的支持可以很大程度上避免这样的错误，编程任务也变得更有趣。F#提供了对计量单位的静态检查，并且封装了国际单位制的各个单位和物理常量，另外我们也可以定义自己的单位；在单位之间进行换算也很简单；此外F#还支持计量单位的泛型。作为对NASA气象卫星的纪念，本文最后给出了一个模拟太阳系的例子 :)&lt;/p&gt;
</description></item><item><title>F# Programming Contest, by Kean at AutoDesk</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#9306219</link><pubDate>Sun, 11 Jan 2009 22:24:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9306219</guid><dc:creator>Don Syme's WebLog on the F# Language and Related Topics</dc:creator><description>&lt;p&gt;Kean over at AutoDesk (think AutoCAD etc.) is running an F# programming contest ! I've included his post&lt;/p&gt;
</description></item><item><title>Konkurs F# i AutoDesk</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#9411624</link><pubDate>Wed, 11 Feb 2009 03:09:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9411624</guid><dc:creator>.neting in the free world</dc:creator><description>&lt;p&gt;Ostatnio ponowiłem wysiłki do opanowania nowych język&amp;#243;w z rodziny MS w tym także implementacji znanych&lt;/p&gt;
</description></item><item><title>Konkurs F# i AutoDesk</title><link>http://blogs.msdn.com/andrewkennedy/archive/2008/09/02/units-of-measure-in-f-part-two-unit-conversions.aspx#9425655</link><pubDate>Mon, 16 Feb 2009 13:12:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9425655</guid><dc:creator>.neting in the free world</dc:creator><description>&lt;p&gt;Ostatnio ponowiłem wysiłki do opanowania nowych język&amp;#243;w z rodziny MS w tym także implementacji znanych&lt;/p&gt;
</description></item></channel></rss>