在F#中创建Array2D(VS2010 Beta 1)

1 arrays f# multidimensional-array

请考虑VS2010 Beta 1中的以下代码片段:

let array = Array2D.zeroCreate 1000 500

这会产生错误,即:

 error FS0030: Value restriction. The value 'array' has been inferred to have 
generic type val array : '_a [,]
Either define 'array' as a simple data term, make it a function with explicit 
arguments or, if you do not intend for it to be generic, add a type annotation.

我可以显式设置类型(在我的例子中是一个字符串网格)?

Joh*_*bom 6

您可以显式指定类似的类型:

let array : string [,] = Array2D.zeroCreate 1000 500
Run Code Online (Sandbox Code Playgroud)

有关值限制的更多信息,您可能需要查看此F#-Wiki页面.