哪些語言特性 設計模式可以優雅地設計相似的演算法?

時間 2022-01-04 09:50:56

1樓:祖與佔

Recursion Schemes: A Field Guide (Redux)

Patterns in Functional Programming

laziness:

In a strict language, it is initially a bit easier to reason about the space and time usage of algorithms, but that superficial ease comes at a price. Compositions of strict algorithms often waste time computing all sorts of things you don't need.

Consider a classic example: take 10

. sort

In a strict language that will do all the work to sort the list, before I decide to only look at the first 10. But in a non-strict language like Haskell with lazy-by-default data structures, it'll only do the work to sort the first 10 elements. If your sort is the "lazy quicksort" or treesort that gets used in practice in Haskell, then this will silently upgrade you to a "quickselect" giving you better asymptotic performance.

via Edward Kmett's answer to What is your review of Haskell (programming language)?

JavaScript 的語言設計有哪些缺陷?

迷途書童 Object instanceof Function true Function instanceof Object true 你中有我,我中有你,理解起來很費勁 Function.constructor Function.constructor.constructor.delete gl...

如何給漢語設計乙個優雅且有歐洲語言既視感的拉丁化方案?

魔法少女蔡徐倫 來段例句 Na endo nyupi.A,na endo nyupi.Kaihwi srma lyan,angban srma lyan.Ni r bur abi a oung ren?Kaihwi srma lyan,angban srma lyan r bur yau dwio ...

將編譯或者程式語言作為畢業設計可以做些什麼?應該如何下手?

只實現個簡單編譯器,只算是編譯原理課程作業級別,當畢設有點勉強了。建議可以考慮在編譯器級別上,多實現一些優化,可能更靠譜一些。同時,語言功能在實現要盡可能完善。如果能完整支援當前乙個主流語言的全部語法,就更贊了。 樸三世 畢設做的就是編譯原理。主要內容是做乙個輔助教學的工具,可供編譯原理課程上演示詞...