开发者

Is it possible to create a global variable in Opa?

开发者 https://www.devze.com 2023-03-14 20:48 出处:网络
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 ac

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消