是Erlang“单一分配”不同于Haskell“不变值” [英] Is Erlang "single assignment" different from Haskell "immutable values"?

查看:86
本文介绍了是Erlang“单一分配”不同于Haskell“不变值”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编程Erlang书中,这种语言使用单个赋值变量。在其他有关函数式编程语言的文章中,我总是读取不可变价值。

In the "Programming Erlang" book it's said that the language uses "single assignment" variables. In other articles about functional programming languages I always read of "immutable values" instead.

单词单一赋值是否意味着与不可变价值不同? p>

Does the wording "single assignment" mean something different from "immutable values"?

推荐答案

在erlang中,变量可以是绑定的还是非绑定的。您只能将值分配给未绑定的变量。这就是单个作业来自哪里,因为一旦变量被绑定,你就不能再为它赋值了。所以在erlang中,即使 0 1 是不可变值,也不能执行以下操作。

In erlang, a variable can be either bound or unbound. You can only assign a value to an unbound variable. And that's where the single assignment comes from, because once the variable is bound, you can no longer assign a new value to it. So in erlang, you can't do the following, even if 0 and 1 are immutable values.

X = 1.
X = 2. // This is not a valid operation

术语immutable是相对于变量的值,而不是变量本身。所以在某些语言中,您可以将相同的变量赋值为不可变的不同值:

The term immutable is relative to the value of the variable, and not the variable itself. So in some languages, you can assign to the same variable different values that are immutable:

X = immutableValue;
X = anotherImutableValue; // This is a valid operation

编辑:从维基百科

Immutable Object


在面向对象和功能性编程中,一个不可变对象是一个对象,它的状态在创建后不能修改。

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created.

单个作业


单个作业是一个名称绑定的示例,与本文中所述的任务不同,只能完成一旦,通常当创建变量时; 不允许后续重新分配。 [...]通过单个赋值创建,命名值不是变量,而是不可变对象。

Single assignment is an example of name binding and differs from assignment as described in this article in that it can only be done once, usually when the variable is created; no subsequent re-assignment is allowed. [...] Once created by single assignment, named values are not variables but immutable objects.

这篇关于是Erlang“单一分配”不同于Haskell“不变值”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆