
Is Rust functional? - yamafaktory
https://www.fpcomplete.com/blog/2018/10/is-rust-functional
======
wahern
> 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.

And yet creating a _closure_ in those languages is natural and trivial. None
of the higher-order examples he provided in Rust were closures.

Closures are at best clunky in a language without automatic GC and heap
allocation (auto-boxing?). But if you can't readily create and use closures
(i.e. functions that use their lexically bound environment outside their
original execution scope, such as invoking it _after_ _returning_ _it_ from
the defining function) then how could you claim strong support for first-class
functions? You don'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's flavor of C is a strongly functional language
because it supports nested functions.

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't make that natural then it
can't be fairly described as friendly to a functional style. In languages like
Javascript people intuitively do this without even _realizing_ it, which is
about as natural as you can get.

