Live data from Hacker News

Functional Language Features in Rust – Iterators and Closures

rust-lang.github.io

11–20 of 42 posts

Re: Functional Language Features in Rust – Iterators and Closures

#11
post #10

Earlier quoted context omitted.

This is why we say > We're going to sidestep the issue of what, exactly, functional programming is or is not, and instead show off some features of Rust that are similar to features in many languages referred to as functional. Many people think of "programming with higher order functions" to be a feature of functional languages, and that may be wrong, but it's also okay. The goal is to teach the stuff, not worry abou…

OK, but if you avoided calling non-functional patterns part of functional programming, you would avoid invoking the topic of "what constitutes functional programming" altogether.

What specifically does "functional programming" mean to you and why do these features not qualify?

Re: Functional Language Features in Rust – Iterators and Closures

#12
That was really well written. As I was reading through the example code in the section about closures

    let add_one = |x| x + 1;
    let five = add_one(4);
I thought to myself "hmm I wonder what happens if I were to call the code with a float rather than an int?"

Answered my question a few paragraphs down. Kudos.

Is it possible to write a generic closure? i.e something that would add 1 to any numeric type.

Re: Functional Language Features in Rust – Iterators and Closures

#13
post #10

Earlier quoted context omitted.

This is why we say > We're going to sidestep the issue of what, exactly, functional programming is or is not, and instead show off some features of Rust that are similar to features in many languages referred to as functional. Many people think of "programming with higher order functions" to be a feature of functional languages, and that may be wrong, but it's also okay. The goal is to teach the stuff, not worry abou…

OK, but if you avoided calling non-functional patterns part of functional programming, you would avoid invoking the topic of "what constitutes functional programming" altogether.

"OK, but if you just asked me what constitutes functional programming, you could avoid me complaining about what constitutes functional programming"

Re: Functional Language Features in Rust – Iterators and Closures

#15

That was really well written. As I was reading through the example code in the section about closures let add_one = |x| x + 1; let five = add_one(4); I thought to myself "hmm I wonder what happens if I were to call the code with a float rather than an int?" Answered my question a few paragraphs down. Kudos. Is it possible to write a generic closure? i.e something that would add 1 to any numeric type.

Thanks!

To answer your last question, not yet. There was an RFC for this, but it was recently postponed; closures rely heavily on traits and we are in the process of re-doing the internals of the trait system. If I remember the reason correctly.

Re: Functional Language Features in Rust – Iterators and Closures

#17

That was really well written. As I was reading through the example code in the section about closures let add_one = |x| x + 1; let five = add_one(4); I thought to myself "hmm I wonder what happens if I were to call the code with a float rather than an int?" Answered my question a few paragraphs down. Kudos. Is it possible to write a generic closure? i.e something that would add 1 to any numeric type.

> Answered my question a few paragraphs down. Kudos.

I absolutely love it when a blog post, talk, or docs like these do that.

Especially during talks. Often the speaker will say something and it will immediately pop up questions in my mind which I really really want to ask but of course I should wait till the end. And then they answer it in the next slide. Perfect :)

Re: Functional Language Features in Rust – Iterators and Closures

#18
post #10

Earlier quoted context omitted.

This is why we say > We're going to sidestep the issue of what, exactly, functional programming is or is not, and instead show off some features of Rust that are similar to features in many languages referred to as functional. Many people think of "programming with higher order functions" to be a feature of functional languages, and that may be wrong, but it's also okay. The goal is to teach the stuff, not worry abou…

OK, but if you avoided calling non-functional patterns part of functional programming, you would avoid invoking the topic of "what constitutes functional programming" altogether.

OK, but if you avoided disputing the definition of a word the author explicitly said was irrelevant, you would avoid invoking the topic of "what constitutes functional programming" altogether.
Post reply on HN