F# 带测量单位的方法

F# 带测量单位的方法,f#,trigonometry,units-of-measurement,F#,Trigonometry,Units Of Measurement,我正在和F#打交道,试图创建cos的重载,该重载接受带单位的角度 这是我的代码: [<Measure>] type rad [<Measure>] type deg let toRad(x:float<deg>) = (float x) * 3.14159265 / 180.0 |> LanguagePrimitives.FloatWithMeasure<rad> let cos (angle: float<rad>

我正在和F#打交道,试图创建
cos
的重载,该重载接受带单位的角度

这是我的代码:

[<Measure>] type rad
[<Measure>] type deg
let toRad(x:float<deg>) =
    (float x) * 3.14159265 / 180.0
    |> LanguagePrimitives.FloatWithMeasure<rad>
let cos (angle: float<rad>) = cos(float angle)
let cos (angle: float<deg>) = cos(toRad angle) // get duplicate definition of cos here
[]类型rad
[]型deg
让toRad(x:浮动)=
(浮动x)*3.14159265/180.0
|>LanguagePrimitives.FloatWithMeasure
设cos(角度:浮动)=cos(浮动角度)
让cos(angle:float)=cos(toRad angle)//在这里得到cos的重复定义
编译器抱怨最后一行的cos定义重复。

度量值类型被删除(请参阅),因此实际上有两个导致错误的定义
cos(角度:浮点)

您可以为这两种可能性创建联合类型

type Angle = Degrees of float | Radians of float
或者为函数指定不同的名称。

出现了什么问题(如果有)?