F#度量单位,通用性问题2 [英] F# Units of measure, problems with genericity 2

查看:42
本文介绍了F#度量单位,通用性问题2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着这个问题,我似乎还是与可能的前沿作斗争,尽管我不认为我在做任何特别前沿的事情:

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> }

给我错误FS0039:未定义计量单位参数'u'.

还有

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

给我错误FS0191:此声明中不允许使用匿名计量单位变量.

函数可以处理通用"度量单位,但类型不能吗?

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

推荐答案

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

应该可以解决问题

注意:从1.9.6.2 CTP版本开始,这是正确的,但是此api当前不被视为稳定的

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

这篇关于F#度量单位,通用性问题2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆