2011-06-23 28 views

回答

3

答案是否定的。如果你有像下面這樣的函數,lambda不會被內聯。 在下面的代碼lambda表達式使用FSharpFunc<,>.InvokeFast()

let fold f s l = 
    let rec loop acc l = 
     match l with []->acc |h::t->loop (f acc h) t 
    loop s l 

let list = [1;2;3;4] 

list|>fold (fun acc x->x+acc) 0|>printfn "%d" 
list|>fold (fun acc x->x*acc) 1|>printfn "%d" 

調用但是,如果您標記fold功能inline形勢的變化。不僅fold函數被內聯,而且lambda也被內聯。我使用.NET Reflector來確認。

相關問題