DEV Community

loading...

Discussion on: Why I don't believe in pure functional programming anymore

Collapse
zilti profile image
Daniel Ziltener

Again, in Rust, ownership makes it clear what things are accessing it.

Ownership in Rust is pretty much the same thing as having variables belong to a class in object oriented languages, from what I understood. As soon as you modified a variable, everything you ever gave this variable to now implicitly has this modified version. This is very different from the functional programming approach where you explicitly have to give the modified variant of the collection to every place you want to see the modification.

Are you aware of Idris, a remake of Haskell that retains pure functional programming but isn't lazy everywhere?

I am aware, but I never used it, and also don't really plan to - same as how I did look into Haskell a little, but opted not to use it; these days I am a Clojure user.

laziness and functional purity are not as intertwined as you seem to think.

They aren't as intertwined, but they are both part of the concepts of functional programming.

Thread Thread
maan2003 profile image
Maan2003 • Edited
pub struct Immut<T>(T);
impl<T> std::ops::Deref for Immut<T> {
  type Target = T;
  fn deref(&self) -> &T { &self.0 }
}
pub fn immut<T>(x: T) -> Immut<T> {
  Immut(x)
}

this guarantees that Immut can't be mutated from outside this module(rust has module level privacy).

Ownership in Rust is pretty much the same thing as having variables belong to a class in object oriented languages, from what I understood. As soon as you modified a variable, everything you ever gave this variable to now implicitly has this modified version. This is very different from the functional programming approach where you explicitly have to give the modified variant of the collection to every place you want to see the modification.

I don't understand what you mean. I would love to see code example.