F# special quotes? (##)

坚强是说给别人听的谎言 提交于 2020-01-10 18:32:38

问题


I just ran across http://frankniemeyer.blogspot.com/2010/04/minimalistic-native-64-bit-array.html Which contains the line

(# "sizeof !0" type('T) : nativeint #)

I believe the technical phrase is "what the heck?" I have never in my (~8 months) of F# programming run across something even resembling that...

FSI tells me something about deprecated constructs, used only for F# libs...

And google with (# does uh...well, not much

Any direction in this?


回答1:


This is the notation for inline IL emission. It used to be a more prominent feature during F#'s earlier years, but has been deprecated. A gentleman named Brian from the F# team has indicated that it is currently used mainly to bootstrap the F# compiler, and that the team had intended to mark this construct as an error, not merely a warning.

See his post here for the full story.




回答2:


It's inline IL (intermediate language) code. This construct is used internally by the F# team to implement bits of the F# core library you just can't do any other way. This code will admit a warning saying it shouldn't be used any where other than the F# core libraries, so you probably don't have to worry about it too much as it should never appear in production code.




回答3:


Fascinating. But I think F# already gives us the conversion operations (for this particular operation!) you need without resorting to IL.

[<Unverifiable>]
let inline ArrayOffset (itemSize:int64) (length:int64) (start:int64) (idx:int64) = 
    if idx < 0L || idx >= length then raise(IndexOutOfRangeException())
    NativePtr.ofNativeInt(nativeint(start + (idx * itemSize)))


来源:https://stackoverflow.com/questions/5888172/f-special-quotes

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