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

查看:13
本文介绍了在 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(未记录)和 --standalone 标志.

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

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

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