如何专门定义特定类型 T 的新数组?
奇怪的是,我找不到任何有关它的有用信息..
我想写这样的东西:
let arr = new Array()
只是 arr 的元素必须是 T 类型。
我怎样才能在 F# 上做到这一点?
最佳答案
也许是 Array.init<'T>
和 Array.create<'T>
功能就是你要找的。
还可以考虑使用 Sequence
而不是数组。
A sequence is a logical series of elements all of one type. Sequences are particularly useful when you have a large, ordered collection of data but do not necessarily expect to use all the elements.
关于arrays - 在 F# 上定义特定类型的新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11049439/