TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Is Rust functional?

5 点作者 yamafaktory超过 6 年前

1 comment

wahern超过 6 年前
&gt; Finally, it’s a bit unfair for me to compare Rust’s facilities here against Haskell. Haskell’s handling of lambdas, closures, first class and higher-order functions is best-in-class, since it’s explicitly the goal of the language. If you compare Rust to most other languages out there, like Javascript, Ruby, or Python, Rust compares even more favorably.<p>And yet creating a <i>closure</i> in those languages is natural and trivial. None of the higher-order examples he provided in Rust were closures.<p>Closures are at best clunky in a language without automatic GC and heap allocation (auto-boxing?). But if you can&#x27;t readily create and use closures (i.e. functions that use their lexically bound environment outside their original execution scope, such as invoking it <i>after</i> <i>returning</i> <i>it</i> from the defining function) then how could you claim strong support for first-class functions? You don&#x27;t have first-class functions; you have closures and non-closures, each with different treatment by the language. Otherwise we could just as well claim that GCC&#x27;s flavor of C is a strongly functional language because it supports nested functions.<p>The defining characteristic, IMO, of functional style programming is using closures to encapsulate and reify state; not the ability to anonymously define functions or functions which can access their lexical environment from within the same execution scope. If the language doesn&#x27;t make that natural then it can&#x27;t be fairly described as friendly to a functional style. In languages like Javascript people intuitively do this without even <i>realizing</i> it, which is about as natural as you can get.