F#计量单位如何运作?

时间:2022-02-24 22:05:42

Has anyone had a chance to dig into how F# Units of Measure work? Is it just type-based chicanery, or are there CLR types hiding underneath that could (potentially) be used from other .net languages? Will it work for any numerical unit, or is it limited to floating point values (which is what all the examples use)?

有没有人有机会深入了解F#计量单位的工作原理?它只是基于类型的chicanery,还是隐藏在下面的CLR类型可能(可能)从其他.net语言使用?它适用于任何数值单位,还是仅限于浮点值(这是所有示例使用的)?

2 个解决方案

#1


11  

According to a response on the next related blog post, they are a purely static mechanism in the F# compiler. So there is no CLR representation of the units data.

根据下一篇相关博客文章的回复,它们是F#编译器中的纯静态机制。因此没有单位数据的CLR表示。

Its not entirely clear whether it currently works with non-float types, but from the perspective of the type system it is theoretically possible.

目前还不完全清楚它是否适用于非浮动类型,但从类型系统的角度来看,它在理论上是可行的。

#2


15  

The best (and I think official) place to find out about this is on Andrew Kennedy's blog.

在安德鲁肯尼迪的博客上,最好的(也是我认为正式的)地方可以找到这个。

Here are the (current) relevant posts.

以下是(当前)相关帖子。

As I said in the post that your answerer referred to, this is most definitely something that you CAN'T do in C# (though I wish you could).

正如我在帖子中所说,你的回答者提到的,这绝对是你在C#中无法做到的事情(虽然我希望你能做到)。

#1


11  

According to a response on the next related blog post, they are a purely static mechanism in the F# compiler. So there is no CLR representation of the units data.

根据下一篇相关博客文章的回复,它们是F#编译器中的纯静态机制。因此没有单位数据的CLR表示。

Its not entirely clear whether it currently works with non-float types, but from the perspective of the type system it is theoretically possible.

目前还不完全清楚它是否适用于非浮动类型,但从类型系统的角度来看,它在理论上是可行的。

#2


15  

The best (and I think official) place to find out about this is on Andrew Kennedy's blog.

在安德鲁肯尼迪的博客上,最好的(也是我认为正式的)地方可以找到这个。

Here are the (current) relevant posts.

以下是(当前)相关帖子。

As I said in the post that your answerer referred to, this is most definitely something that you CAN'T do in C# (though I wish you could).

正如我在帖子中所说,你的回答者提到的,这绝对是你在C#中无法做到的事情(虽然我希望你能做到)。