F#: Unit of Measure and 3rd-party Libraries

As I document my journey of learning F#, I have learned that data that is wrapped by a Unit of Measure can still interact with 3rd party libraries that do not support the Unit of Measure (UOM) feature. I learned of this technique via the following link.


open System

[<Measure>] type ms

let absoluteValue1 = Math.Abs (100<ms>)     // Won't compile
let absoluteValue2 = Math.Abs (int 100<ms>)

In conclusion, I have learned to simply cast the value wrapped by a UOM to the data type that’s required by a 3rd-party library.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s