纯度vs参考透明度 [英] Purity vs Referential transparency

本文介绍了纯度vs参考透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些术语似乎有不同的定义,但我一直认为其中一个暗示另一个;我不能想到任何情况下,当表达是透明的,但不是纯粹的,反之亦然。

维基百科针对这些概念保留了不同的文章,并说:

From 参照透明度


如果
表达式中涉及的所有函数都是纯函数,那么
表达式的引用是透明的
。此外,如果
表达式的值被
丢弃,并且它们的副作用是
无关紧要,那么一些不纯的
函数可以包含在
表达式中。




纯表达式


纯函数需要
构造纯表达式。 [...]纯
表达式通常被称为
,它们是引用透明的。


我发现这些陈述混淆。如果来自所谓的不纯功能的副作用足够小,以致于无法实现它们(即用其 替代对这种功能的调用)改变程序,就好像它是纯粹的一样,不是吗?



是否有更简单的方法来理解纯表达式和一个引用透明的,如果有的话?如果存在差异,则清楚地表明它的示例表达式将被赞赏。

解决方案

如果我在一个地方聚集我熟人的三位理论家,他们中至少有两位不同意这个术语的含义参照透明度。当我还是一个年轻的学生时,我的一位导师给了我一份文件解释说,即使你只考虑专业文献,引用透明一词至少也意味着三种不同的东西。 (不幸的是,纸张位于尚未扫描的重印部分中,我搜索了Google Scholar,但没有成功。)



我无法通知您,但我可以建议你放弃:因为即使是尖头语言理论家的微小干部也不能就它的含义达成一致,所以引用透明这个词是没有用的即可。所以不要使用它。






在任何有关编程语言语义的主题上,维基百科都是不可靠的。我已经放弃了试图解决它;维基人的过程似乎将稳定性和准确性的变化和流行投票视为重要。

The terms do appear to be defined differently, but I've always thought of one implying the other; I can't think of any case when an expression is referentially transparent but not pure, or vice-versa.

Wikipedia maintains separate articles for these concepts and says:

From Referential transparency:

If all functions involved in the expression are pure functions, then the expression is referentially transparent. Also, some impure functions can be included in the expression if their values are discarded and their side effects are insignificant.

From Pure expressions:

Pure functions are required to construct pure expressions. [...] Pure expressions are often referred to as being referentially transparent.

I find these statements confusing. If the side effects from a so-called "impure function" are insignificant enough to allow not performing them (i.e. replace a call to such a function with its value) without materially changing the program, it's the same as if it were pure in the first place, isn't it?

Is there a simpler way to understand the differences between a pure expression and a referentially transparent one, if any? If there is a difference, an example expression that clearly demonstrates it would be appreciated.

解决方案

If I gather in one place any three theorists of my acquaintance, at least two of them disagree on the meaning of the term "referential transparency." And when I was a young student, a mentor of mine gave me a paper explaining that even if you consider only the professional literature, the phrase "referentially transparent" is used to mean at least three different things. (Unfortunately that paper is somewhere in a box of reprints that have yet to be scanned. I searched Google Scholar for it but I had no success.)

I cannot inform you, but I can advise you to give up: Because even the tiny cadre of pointy-headed language theorists can't agree on what it means, the term "referentially transparent" is not useful. So don't use it.


P.S. On any topic to do with the semantics of programming languages, Wikipedia is unreliable. I have given up trying to fix it; the Wikipedian process seems to regard change and popular voting over stability and accuracy.

这篇关于纯度vs参考透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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