Array module empty array return values

Dec 20, 2014 at 12:04 AM
I think we missed this when code reviewing the collections API PRs, but want to confirm/discuss.
  • For F# 3.1 (and I assume earlier), all arrays returned from the various Array module functions were freshly allocated, including empty arrays. The singleton [| |] / Array.empty is never returned from a processing function.
  • For some of the F# 4.0 APIs, optimizations/shortcuts/special cases were used which return the singleton instance when it’s known that the result will be an empty array.
Should these new guys all be “fixed” to return a fresh empty array? Although it seems safe/optimized to use a singleton, even for arrays, my hunch is that this pattern is intentional.
Dec 20, 2014 at 3:31 AM
I think they do not need fixing. Not allocating a fresh empty array seems like the right thing.