Is it possible to create a global variable in Opa?

In the new programming language OpStation MLState can create a global variable?

+5
source share
1 answer

Opa is a functional language, so there are no global variables in the language. However, similar behavior can be achieved with Mutable. At the top level, a value is declared using:

global_var = Mutable.make(initial_value)

where initial_valueis the initial value for the variable (of some type t). Then you can get the value with:

global_var.get()

and install it with:

global_var.set(new_value)

See the Opa API Overview for more information .

, , ; Opa (. Opa ).

+5

All Articles