开发者

Is it possible to create a global variable in Opa?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜