News for hackers. Stuff that matters.
Re:Ask HN: Why Isn't Functional Programming Taking Over? by elamje on Tuesday April 02, 2019 @01:07AM (#19551256)
I’ve never heard of rust being used in the functional world, interesting.
Re:Ask HN: Why Isn't Functional Programming Taking Over? by SamReidHughes on Tuesday April 02, 2019 @01:37AM (#19551345)
Rust is arguably a pure functional language if you take out UnsafeCell and system calls.
Re:Ask HN: Why Isn't Functional Programming Taking Over? by millstone on Tuesday April 02, 2019 @01:43AM (#19551369)
No way. Rust supports mutation, does not have referential transparency, etc.
Re:Ask HN: Why Isn't Functional Programming Taking Over? by SamReidHughes on Tuesday April 02, 2019 @01:48AM (#19551390)
Rust functions perform mutation by consuming the parameter and emitting a new one in its place, effectively. You can take any data type and build an alternate version of it that can be used without using mut (and with a much less convenient API, but it’s basically a rote transformation of the code).

Edit: I’d nominate as a good definition of pure functional programming the absence of undeclared data flow (i.e. side effects) by your code.

Re:Ask HN: Why Isn't Functional Programming Taking Over? by millstone on Tuesday April 02, 2019 @02:11AM (#19551471)
Give me a break. I can increment a variable in Rust.

Yes you can perform an SSA-versioned-variables or linear-types-changing-the-world transformation. That's just sophism; we can conclude that C is pure functional via the same line of argument.

In response to your edit: Rust does not encode side effects in its type system and does not require system calls to achieve side effects. If that's your point then we're in agreement.

Re:Ask HN: Why Isn't Functional Programming Taking Over? by SamReidHughes on Tuesday April 02, 2019 @02:23AM (#19551517)
You can’t do that with C. Nor can you do that with Rust, because it has UnsafeCell. In the absence of UnsafeCell and system calls (and, I guess, unsafe blocks), Rust encodes “all” its side effects (conservatively, and not trivially conservatively). All of its information flow, anyway.
Re:Ask HN: Why Isn't Functional Programming Taking Over? by millstone on Tuesday April 02, 2019 @02:43AM (#19551597)
It's trivial in Rust to share mutable memory via RefCell, Rc, others. These are core, not exotic.

We can imagine a language in which these don't exist, but it's not Rust and would not enjoy the ergonomics of Rust. That's why Rust is not pure functional, or even "almost" pure functional.

Re:Ask HN: Why Isn't Functional Programming Taking Over? by SamReidHughes on Tuesday April 02, 2019 @03:24PM (#19557702)
RefCell uses UnsafeCell inside. Everything that does mutation, under shared ownership, has UnsafeCell somewhere -- IIRC this is or was a requirement to guarantee the compiler won't do certain optimizations.

> but it's not Rust

That's why I stipulated Rust without UnsafeCell.