來自F#News的post指出F#可以內聯一個作爲參數傳遞的函數。 情況總是如此嗎?它會自動發生嗎?F#中的所有lambda參數都被自動內聯#
3
A
回答
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來確認。
2
我不知道編譯器對高階函數做了哪些優化,但本文似乎指的是明確標記爲inline
的類型廣義函數。這是爲了支持statically resolved type parameters。
相關問題
- 1. F中的無參數lambda表達式#
- 2. 內聯Ckeditor:所有按鈕都被禁用
- 3. 來自不同類的內聯類函數,都是內聯的?
- 4. 在收集排序參數中帶有自動類型的Lambda
- 5. 聯機參考:C#中的所有內置函數?
- 6. 並非所有來自logstash的數據都被索引indexsearch
- 7. 爲什麼不是所有函數都內聯?
- 8. 所有值都被覆蓋
- 9. 自動網址參數添加到所有內部鏈接
- 10. f:來自CommandButton的參數沒有得到參數
- 11. 是否所有內核都自動使用?
- 12. 所有重構都參數化了嗎?
- 13. 自動生成C#項目的所有內聯XML文檔
- 14. rm -f不會處理bash腳本中的所有參數
- 15. GIT並非所有的參考文獻都已被推送
- 16. 發佈git clean -f時,我的所有文件都被刪除了嗎?
- 17. 那麼,F#中的所有表達式都是?
- 18. 有時F#不會內聯函數,即使它被標記爲「inline」?
- 19. F#中重載的內聯運算符:(| + |)
- 20. 如何確保Pytorch中的所有內容都自動運行在GPU上?
- 21. VC++自動內聯?
- 22. 所有的鏈接都被重定向
- 23. F#Lambda簽名
- 24. 是否所有類名都保證在所有JVM中都被實現?
- 25. linq表達式中的內聯lambda?
- 26. 內部函數F,使用參數F之類的參數來更新()
- 27. 如何改變js中所有參數都是對象的函數參數?
- 28. 聯動的內聯函數
- 29. 如何在lambda表達式中添加內聯條件聯合/自聯接?
- 30. 可以HotSpot內聯lambda函數調用?