Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何为非泛型数组定义扩展方法?_Arrays_F#_Extension Methods - Fatal编程技术网

Arrays 如何为非泛型数组定义扩展方法?

Arrays 如何为非泛型数组定义扩展方法?,arrays,f#,extension-methods,Arrays,F#,Extension Methods,我不知道在非泛型数组上定义扩展方法的正确语法是什么。处理泛型数组,但对字节数组尝试类似的构造是行不通的 我尝试了很多选择: type Byte ``[]`` with type byte ``[]`` with type Byte array with type byte array with type array<Byte> with type array<byte> with type []<Byte> with type []<byte>

我不知道在非泛型数组上定义扩展方法的正确语法是什么。处理泛型数组,但对字节数组尝试类似的构造是行不通的

我尝试了很多选择:

type Byte ``[]`` with 
type byte ``[]`` with
type Byte array with
type byte array with
type array<Byte> with
type array<byte> with
type []<Byte> with
type []<byte> with
用
键入字节“`[]``和
使用
使用
使用
使用
键入[]带
键入[]带

以及所有这些用双反勾号或括号包装的构造,但都不起作用。我下载了语言规范,但它只有一个通用的数组示例。

这可能是一个带有可选类型扩展的怪癖,它是。我将使用如下扩展方法:

open System.Runtime.CompilerServices

[<Extension>]
type ByteArrayExtensions =
    [<Extension>]
    static member inline Sum(xs: byte[]) = Array.sum xs

let f() =
    let xs = [| byte(1); byte(2); byte(3) |]
    xs.Sum()
open System.Runtime.CompilerServices
[]
键入ByteArrayExtensions=
[]
静态成员内联和(xs:byte[])=Array.Sum xs
设f()=
设xs=[|字节(1);字节(2);字节(3)|]
xs.Sum()

这可能是一个带有可选类型扩展名的怪癖,它可以。我将使用如下扩展方法:

open System.Runtime.CompilerServices

[<Extension>]
type ByteArrayExtensions =
    [<Extension>]
    static member inline Sum(xs: byte[]) = Array.sum xs

let f() =
    let xs = [| byte(1); byte(2); byte(3) |]
    xs.Sum()
open System.Runtime.CompilerServices
[]
键入ByteArrayExtensions=
[]
静态成员内联和(xs:byte[])=Array.Sum xs
设f()=
设xs=[|字节(1);字节(2);字节(3)|]
xs.Sum()

你试过
字节[]
?@FyodorSoikin是的,运气不好。你试过
字节[]
?@FyodorSoikin是的,运气不好。