Algebraic Effects also allow you to make ‘mutable’ variables in languages without mutable variables. ^.^
Here’s a playground of Algebraic Effects I made in Elixir:
And here’s an implementation of a ‘mutable’ variable in that effects system:
defmodule State do
import ElixirEffects
defmodule Get do
ElixirEffects.defeffect
end
defmodule Set do
ElixirEffects.defeffect [:value]
end
def get, do: perform %Get{}
def set(value), do: perform %Set{value: value}
def run(init, fun) do
run_effect init, fun.() do
state, %Get{} -> {:return, state}
state, %Set{value: new_state} -> {:return, new_state, state} # Return old state
end
end
end
So this defines a State
effect, which can then be used like:
State.run 0, fn ->
import State
assert 0 = get()
assert 0 = set(42)
assert 42 = get()
6.28
end
The first argument to State.run
is the initial value of the ‘variable’, at which point you can then get and set it all you want. You could even ‘key’ it based on a name or something and get multiples too!
For note, any mutable variable system can be emulated with immutable variables. look at even C/C++, they are as mutable as you can get, but they lower down to (in clang) the LLVM Assembly language, which is entirely immutable (but it’s optimizers optimize into mutable machine code, but it itself is immutable to simplify optimizations and implementations). 
As an aside, the effects system is able to handle a lot more than just fake mutation, they are an entirely powerful construct. Sadly mine is not fully capable because of BEAM VM limitations (no continuations so to compensate I’d have to recompile effectful code as CPS or wrap everything up into a new process, which is entirely doable, just a lot more work that I don’t have time to do in such a simple playground).