相关疑难解决方法(0)

在F#标准库实现中看到的(#...#)语法是什么?

阅读Array2D模块的源代码,我在许多核心函数的实现中偶然发现了这个有趣的结构,例如:

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

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

warning FS0042: This construct is deprecated: it is only for use in the F# library
Run Code Online (Sandbox Code Playgroud)

究竟是什么?有没有详细的文件?

f# cil

23
推荐指数
2
解决办法
1415
查看次数

如何使用具有静态解析类型参数的静态扩展方法?

我想使用静态解析的类型参数和我添加到内置类型的一些扩展方法,比如float32int32,所以我尝试了以下方法:

module Foo =
    type System.Single with
        static member Bar x = x + 1.0f

    let inline bar (x : ^a) =
        (^a : (static member Bar : ^a -> ^a) x)

open Foo
[<EntryPoint>]
let main argv =
    System.Console.WriteLine (bar 1.0f) (* Compilation fails here *)
    0
Run Code Online (Sandbox Code Playgroud)

编译器抱怨说The type 'float32' doesn't support the operator 'Bar'.我究竟做错了什么?

extension-methods f# operators

6
推荐指数
1
解决办法
234
查看次数

标签 统计

f# ×2

cil ×1

extension-methods ×1

operators ×1