4 ms·
> Functional programming languages do not capture mutable state in closures. Yes, they can. In ML, you can build a function that returns a set of closures tha
by tempodox 9y ago
> Functional programming languages do not capture mutable state in closures.
Yes, they can. In ML, you can build a function that returns a set of closures that manipulate or use shared mutable state. I'm quite sure you can do something equivalent in Haskell, too.
As always, “it depends” whether you would actually want to do that.
- willtim 9y agoThe reference type in ML/OCaml is an opt-in feature, a container with it's own special type. In Haskell, you can also capture IORefs or similar, but any reads/writes to them are effectful and captured in the types. The point is that Python does this all the time as the default. Any captured variable could potentially change under your feet. It is rarely useful and most beginners do not expect it, hence it is commonly considered a "gotcha".