Hacker News new | past | comments | ask | show | jobs | submit login

Rust 'does' lazy evaluation only in the sense that you can implement it if you go out of your way. It's not the default like in Haskell. It's not a functional programming language–having functors, monoids, and monads (in some restricted sense) doesn't make a language FP.



Lazy evaluation is not a requirement of functional programming. There's nothing really in typed lambda calculus requiring any laziness, that's just one possible way of expression evaluation.

The only real requirement of functional programming is the support of first class functions, the possibility to pass and return functions like any other values.

If you want to discuss your own interpretation of what makes a language more or less functional, which could be interesting, please provide a definition first.


Note that I didn't say that lazy evaluation is needed for functional programming. I said that Rust doesn't have lazy evaluation, and that it's not a functional programming language.

IMHO, a functional programming language requires:

- First-class functions and function literal (lambda) syntax support

- Expression-oriented syntax

- Emphasis on immutable data structures

- Tail call optimization

Other features are 'take-it-or-leave-it'.


So given that ML languages don't require tail call optimizations, and allow for mutable data structures....


AFAIK all ML languages support tail call optimization, and put the emphasis on immutable data structures.


Nope, Scheme is one of the few languages that require tail call optimisation as per language standard.

There is no emphasis when mutability is one mut and ref cell away.


OCaml doesn't have a language standard afaik, and its implementation(s) support(s) TCO, so imho that's more important.

'Emphasis' just means the 'paved path', i.e. default data structures like records and variants are immutable, default list type is immutable. Of course if you want mutable stuff it's there, but it's not the default.


Even so, OCaml isn't all ML languages.


Afaik all ML languages have TCO, let me know if I'm wrong.


> The only real requirement of functional programming is the support of first class functions, the possibility to pass and return functions like any other values.

By that definition C language supports functional programming. I think a lot of people would disagree with your definition.


It does. I enjoyed the book Functional C by Hartel & Muller a lot:

https://www.semanticscholar.org/paper/Functional-C-Hartel-Mu...

It uses SML, had fun learning this stuff on the train with termux and vim.


Actually, first class functions also means the ability to form functions (ie, closures). Javascript for instance has that feature. I think that python also supports it. C OTOH doesn't, but it has other advantages.


Basic implementation for car, cdr, map with function pointers and clang blocks, the rest of Lispy stuff is left as an exercise. :)

https://godbolt.org/z/Y5qWs4c64


That's cool!

C++ had support for partial applications with templates (std::bind iirc), and it was possible to implement closures as objects with the () operator implemented. Now it has support for closure with a dedicated syntax.

It would be possible to do something similar in C - a closure is just a function pointer and a bunch of parameters bundled together, but I don't think there's enough flexibility in the language to make it look like regular function calls.


I don't think it's particularly out of the way. Iterators are a normal part of rust, and are lazy.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: