F# Units of measure, problems with genericity 2

五迷三道 提交于 2019-12-25 01:15:19

问题


Following on from this question, I still seem to be battling at the frontiers of what is possible, though I don't think that I'm doing anything particularly bleeding edge:

type Vector2d = { X: float<'u>; Y: float<'u> }

Gives me error FS0039: The unit-of-measure parameter 'u' is not defined.

And

type Vector2d = { X: float<_>; Y: float<_> }

Gives me error FS0191: anonymous unit-of-measure variables are not permitted in this declaration.

Is it the case that functions can handle 'generic' units of measure, but types can't?


回答1:


type Vector2d<[<Measure>]'u> = { X: float<'u>; Y: float<'u> }

should do the trick

Note: This is correct as of the 1.9.6.2 CTP release but this api is not currently viewed as stable



来源:https://stackoverflow.com/questions/490780/f-units-of-measure-problems-with-genericity-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!