How do F# units of measure work?

后端 未结 2 496
囚心锁ツ
囚心锁ツ 2020-12-14 09:47

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

相关标签:
2条回答
  • 2020-12-14 10:27

    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.

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

    0 讨论(0)
  • 2020-12-14 10:44

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

    Here are the (current) relevant posts.

    • Units of Measure in F#: Part One, Introducing Units
    • Units of Measure in F#: Part Two, Unit Conversions
    • Units of Measure in F#: Part Three, Generic Units
    • Units of Measure in F#: Part Four, Parameterized Types

    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).

    0 讨论(0)
提交回复
热议问题