List.map每次都会分配一个新的List吗?

Sim*_* V. 2 f#

让我们考虑以下列表:

// 2 2 2 1 1 1
let xs = [2;2;2;1;1;1]

// 2 2 2 1 1 1
let xs' = List.map (fun x -> x) list

// 4 4 4 1 1 1
let xs'' = List.map (fun x -> x * x) list
Run Code Online (Sandbox Code Playgroud)

List.map在第二种情况下分配一个新列表吗?在第三种情况下,将xs分享尾巴[1;1;1]xs''

Joh*_*mer 5

标准库倾向于使用此类函数的简单实现.

结果,没有完成这种类型的优化.

可以在此处找到实现:https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/local.fs#L85