//[snippet:"Core Definition"] #nowarn "42" open System [] type bool<[] 'm> = bool [] type uint64<[] 'm> = uint64 [] type Guid<[] 'm> = Guid [] type string<[] 'm> = string [] type TimeSpan<[] 'm> = TimeSpan [] type DateTime<[] 'm> = DateTime [] type DateTimeOffset<[] 'm> = DateTimeOffset type UnitOfMeasureTC = // Method signatures declare a type relationship between // units of measure of the same underlying type // NB underlying types in UoM arguments should always match static member IsUnitOfMeasure(_ : bool<'a>, _ : bool<'b>) = () static member IsUnitOfMeasure(_ : int<'a>, _ : int<'b>) = () static member IsUnitOfMeasure(_ : int64<'a>, _ : int64<'b>) = () static member IsUnitOfMeasure(_ : uint64<'a>, _ : uint64<'b>) = () static member IsUnitOfMeasure(_ : float<'a>, _ : float<'b>) = () static member IsUnitOfMeasure(_ : decimal<'a>, _ : decimal<'b>) = () static member IsUnitOfMeasure(_ : Guid<'a>, _ : Guid<'b>) = () static member IsUnitOfMeasure(_ : string<'a>, _ : string<'b>) = () static member IsUnitOfMeasure(_ : TimeSpan<'a>, _ : TimeSpan<'b>) = () static member IsUnitOfMeasure(_ : DateTime<'a>, _ : DateTime<'b>) = () static member IsUnitOfMeasure(_ : DateTimeOffset<'a>, _ : DateTimeOffset<'b>) = () [] module UnitOfMeasure = let inline private _cast< ^TC, ^a, ^b when (^TC or ^a or ^b) : (static member IsUnitOfMeasure : ^a * ^b -> unit)> (t : ^a) = (# "" t : ^b #) /// generic unit of measure cast function let inline cast (x : 'a) : 'b = _cast x //[/snippet] //[snippet:"Examples"] [] type m [] type n let x : string = UnitOfMeasure.cast "string" let y : string = UnitOfMeasure.cast x let z : string = UnitOfMeasure.cast y [] type Foo<[] 'm> = Foo and Foo = Foo with static member IsUnitOfMeasure(x : Foo<'m>, y : Foo<'n>) = () let foo : Foo = UnitOfMeasure.cast Foo //[/snippet]