在F#标准库实现中看到的(#...#)语法是什么? [英] What is the (# ... #) syntax seen in F# standard library implementation?

查看:69
本文介绍了在F#标准库实现中看到的(#...#)语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Array2D模块的源代码时,我偶然发现了这种有趣的构造,可以实现许多核心功能,例如:

Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example:

[<CompiledName("Get")>]
let get (array: 'T[,]) (n:int) (m:int) =  (# "ldelem.multi 2 !0" type ('T) array n m : 'T #)  

我只能假设这是内联CIL,显然在这里用于获得性能优势。但是,当我尝试在程序中使用此语法时,出现错误:

I can only assume that this is the syntax to inline CIL and is used here obviously to gain performance benefits. However, when I've tried to use this syntax in my program, I get an error:

warning FS0042: This construct is deprecated: it is only for use in the F# library

这到底是什么?有没有详细的文档?

What exactly is this? Is there any detailed documentation?

推荐答案

我认为这有两个目的:


  1. 这些函数可以精确地编译为1条CIL指令,必须在某处进行编码,因此在源代码处进行编码似乎是最好的。

  2. 它允许一些通过高性能定义多态 Add 函数来进行额外的欺骗,这在F#类型系统中很难做到。

  1. These functions compile down to exactly 1 CIL instruction which has to be encoded somewhere, so encoding at the source seems best.
  2. It allows for some extra trickery with defining polymorphic Add functions in a high performance way which is hard with the F# type system.

您可以实际使用它,但必须指定-compiling-fslib (未记录)和-独立代码中的标志。

You can actually use this but you have to specify the --compiling-fslib (undocumented) and --standalone flags in your code.

这篇关于在F#标准库实现中看到的(#...#)语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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