In MLState's new programming language Opa, is it possible to create a global variable?
Opa is a functional language so there are no global variables in the language. However, one can achieve a similar behavior with Mutable
. At top-level one declares the value with:
global_var = Mutable.make(initial_value)
where initial_value
is the initial value for the variable (of some type t
). Then one can retrieve the value with:
global_var.get()
and set it with:
global_var.set(new_value)
More information in the Opa API overview.
Note however, that this mechanism should be used only in special situations; the primary device of encapsulating state in Opa are its distributed sessions (see the Opa manual for more on that subject).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With