单一作业的目的 [英] The Purpose of Single Assignment

查看:90
本文介绍了单一作业的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图掌握Erlang。这是我研究的第一个函数式编程语言,我注意到,在Erlang中,您所做的每个作业都是单个作业。显然,不仅仅是在Erlang,而且在许多其他功能性的编程语言中,任务是通过单独的分配完成的。



我真的很困惑他们为什么这样做。单一作业的目的是什么?可以从中获得什么好处?

解决方案

不可变性(你称之为单一作业),简化了很多事情,因为它需要从您的程序中删除时间变量。



例如,在数学中,如果你说

  x = y 

您可以替换 x y ,无处不在。在操作编程语言中,您无法确保此等式成立:存在与每行代码相关联的时间(状态)。这个时间状态也让门打开了不需要的副作用,这是敌方号码一个模块化和并发性。



有关更多信息,请参阅: http://mitpress.mit.edu/sicp/full-text/book/book-ZH-20.html#%_sec_3.1.1


I'm currently trying to master Erlang. It's the first functional programming language that I look into and I noticed that in Erlang, each assignments that you do is a single assignment. And apparently, not just in Erlang, but in many other functional programming languages, assignments are done through single assignment.

I'm really confused about why they made it like that. What exactly is the purpose of single assignment? What benefits can we get from it?

解决方案

Immutability (what you call single assignment), simplifies a lot of things because it takes out the "time" variable from your programs.

For example, in mathematics if you say

  x = y

You can replace x for y, everywhere. In operational programming languages you can't ensure that this equality holds: there is a "time" (state) associated with each line of code. This time state also leaves the door open to undesired side effects which is the enemy number one of modularity and concurrency.

For more information see this: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%_sec_3.1.1

这篇关于单一作业的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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