Hacker News new | ask | show | jobs
by nextaccountic 931 days ago
> Region-based Local Mutation

> Flix supports region-based local mutation, which makes it possible to implement pure functions that internally uses mutable state and destructive operations, as long as these operations are confined to the region.

> We can use local mutation when it is more natural to write a function using mutable data and in a familiar imperative-style while still remaining pure to the outside world.

> We can also use local mutation when it is more efficient to use mutable data structures, e.g. when implementing a sorting algorithm.

Another language with a feature like this is F* (or FStar), but I think it uses a different kind of compile-time analysis.

Haskell actually kind of lets you do it through the ST monad (there's a function called runST that turns mutable code inside the ST monad into pure code). But F* (and Flix) can do it implicitly

1 comments

I wish Erlang/Elixir would allow this.

An Erlang/Elixir process is single-threaded by definition, so there is no contention and in-place mutation could be allowed.