什么是参照透明度? [英] What is referential transparency?

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

问题描述

术语参考透明度是什么意思?我听说它被描述为它意味着你可以用等号代替等于,但这似乎是一个不充分的解释。 解决方案

术语参考透明度来自分析哲学,它是分析自然语言结构的哲学分支,基于逻辑和数学方法的陈述和论据。换句话说,它是计算机科学以外最接近我们所称的编程语言语义的主题。哲学家奎因负责启动参照透明度的概念,但这也是隐含的方法伯特兰罗素和阿尔弗雷德怀特黑德。

参照透明度的核心是一个非常简单和清晰的概念。术语指称对象在分析哲学中用于讨论表达式引用的内容。它与我们在编程语言语义中的含义或外延所表示的意思大致相同。使用安德鲁Birkett的例子(博客文章)中,术语苏格兰的首都指的是爱丁堡市。这是一个指涉的简单例子。



如果用另一个术语替换该术语中的术语,则该术语中的上下文是引用透明的指的是相同的实体不会改变含义。例如


苏格兰议会在苏格兰首都举行会议。


的含义与


相同。苏格兰议会在爱丁堡举行会议。

blockquote>

因此,苏格兰议会在......会面......的背景是一个引用透明的背景。我们可以用爱丁堡取代苏格兰的首都而不会改变其含义。换句话说,上下文只关心该术语所指的内容而没有其他内容。这是上下文引用透明的意义。



另一方面,在句子中,


爱丁堡自1999年以来一直是苏格兰的首都。

我们不能这样做替代。如果我们这样做了,我们会得到爱丁堡自1999年以来一直是爱丁堡,这是一个可笑的话,并没有传达出与原始句子相同的含义。因此,似乎爱丁堡自1999年以来......的背景似乎是不透明的(与之相对的是透明的)。它显然比这个术语所指的更多。它是什么?



像苏格兰首都这样的东西叫做明确的术语,它们不会给逻辑学家带来头疼的痛苦和哲学家很长一段时间。罗素和奎因将他们排除在外,说他们实际上不是指称的,即认为上述例子被用来指代实体是错误的。了解上述句子的正确方法是说,自1999年以来,苏格兰已经拥有资本,并且首都是爱丁堡。


这句话不能转化为坚果。问题解决了!奎因的观点是说自然语言是混乱的,或者说至少是复杂的,因为它是为了实际使用而方便的,但哲学家和逻辑学家应该以正确的方式理解它们,以澄清它们。引用透明度是一种工具,可用来实现这种明确的含义。



这与编程有什么关系?其实不是很多。正如我们所说的,参照透明度是一种用于理解语言的工具,即分配的含义。创建编程语言语义学领域的克里斯托弗斯特拉奇将其用于意义研究。他的基础论文编程语言的基本概念网络。这是一篇漂亮的论文,每个人都可以阅读和理解它。所以,请这样做。你会很开明。他在本段中引入了参照透明度一词:


表达式最有用的属性之一是由Quine [4]参考
透明度。实际上,这意味着如果我们希望找到
包含一个子表达式的表达式的值,我们需要知道的子表达式的唯一值就是它的
值。子表达式的任何其他特征,比如它的内部结构,数字
和它的组件的性质,它们被评估的顺序或者它们被写入的墨水颜色
,与主表达式的值无关。


使用本质表明Strachey解释它以解释它简单地说。功能程序员似乎以他们自己的方式理解了这一段。在论文中还有9个参照透明度的事件,但他们似乎没有考虑其他任何事情。事实上,Strachey的整篇论文致力于解释命令式编程语言的含义。但是,今天,函数式程序员声称,命令式编程语言不是是透明的。 Strachey将转入他的坟墓。



我们可以挽救这种情况。我们说自然语言是杂乱的,或者至少是复杂的,因为它被制作成便于实际使用。编程语言也是一样。它们是杂乱的,或者至少是复杂的,因为它们被设计成便于实际使用。这并不意味着他们需要混淆我们。他们必须以正确的方式理解,使用一种偏向透明的元语言,以便我们具有明确的含义。在我引用的论文中,斯特拉奇完全是这样。他通过将命令式编程语言分解为基本概念来解释命令式编程语言的含义,在任何地方都不会失去清晰度他的分析的一个重要部分是指出编程语言中的变量有两种值,称为 l值 r值。在Strachey的论文之前,这个问题并没有被理解,而且混乱是至高无上的。今天,C的定义经常提到它,每个C程序员都明白这个区别。 (其他语言的程序员是否同样理解它也很难说)。

Quine和Strachey都关心语言构造的含义,这涉及到某种形式的上下文-dependence。例如,我们的例子爱丁堡自1999年以来一直是苏格兰的首都表示苏格兰首都取决于考虑时间。无论是在自然语言还是编程语言中,这样的上下文依赖都是现实。即使在函数式编程中,自由和绑定变量也要根据它们出现的上下文来解释。任何类型的上下文依赖都会以某种方式阻止参考透明。如果您试图理解术语的含义而不考虑它们所依赖的上下文,那么您最终会产生混淆。奎因关心模态逻辑的含义。他认为模态逻辑是不透明的,应该通过将其翻译成一个引用透明的框架(例如,通过将必要性视为可证明性)。他很大程度上失去了这场辩论逻辑学家和哲学家都认为克里普克可能的世界语义是完全足够的。类似的情况也符合命令式编程。由Strachey解释的状态依赖和由Reynolds解释的存储依赖(以与Kripke可能的世界语义类似的方式)是完全足够的。功能程序员不太了解这些研究。他们关于参考透明度的想法应该采用大量的盐。

<附加说明:上面的例子说明了一个简单的词组,例如苏格兰首都有多层含义。在一个层面上,我们可能会谈论当前的资本。在另一个层面上,我们可能会谈论苏格兰可能经历的所有可能的首都。在正常实践中,我们可以放大一个特定的上下文,并缩小以很容易地跨越所有上下文。自然语言的效率利用了我们的能力。命令式编程语言的效率非常类似。我们可以在赋值的右侧( r-value )使用变量 x 来在特定状态下讨论它的值。或者,我们可以讨论它横跨所有状态的 l-value 。人们很少被这样的事情困惑。然而,他们可能或不可能精确地解释语言结构中固有的所有层意义。所有这些层面的意义不一定是明显的,并且正确地研究它们是科学的问题。然而,普通人不明白这种分层含义并不意味着他们对此感到困惑。]

下面的一个单独的postscript与此相关讨论功能和命令式编程的问题。

What does the term referential transparency mean? I've heard it described as "it means you can replace equals with equals" but this seems like an inadequate explanation.

解决方案

The term "referential transparency" comes from analytical philosophy, the branch of philosophy that analyzes natural language constructs, statements and arguments based on the methods of logic and mathematics. In other words, it is the closest subject outside computer science to what we call programming language semantics. The philosopher Quine was responsible for initiating the concept of referential transparency, but it was also implicit in the approaches of Bertrand Russell and Alfred Whitehead.

At its core, "referential transparency" is a very simple and clear idea. The term "referent" is used in analytical philosophy to talk about the thing that an expression refers to. It is roughly the same as what we mean by "meaning" or "denotation" in programming language semantics. Using Andrew Birkett's example (blog post), the term "the capital of Scotland" refers to the city of Edinburgh. That is a straightforward example of a "referent".

A context in a sentence is "referentially transparent" if replacing a term in that context by another term that refers to the same entity doesn't alter the meaning. For example

The Scottish Parliament meets in the capital of Scotland.

means the same as

The Scottish Parliament meets in Edinburgh.

So the context "The Scottish Parliament meets in ..." is a referentially transparent context. We can replace "the capital of Scotland" with "Edinburgh" without altering the meaning. To put another way, the context only cares about what the term refers to and nothing else. That is the sense in which the context is "referentially transparent."

On the other hand, in the sentence,

Edinburgh has been the capital of Scotland since 1999.

we can't do such a replacement. If we did, we would get "Edinburgh has been Edinburgh since 1999", which is a nutty thing to say, and doesn't convey the same meaning as the original sentence. So, it would seem that the context "Edinburgh has been ... since 1999" is referentially opaque (the opposite of referentially transparent). It apparently cares about something more than what the term refers to. What is it?

Things such as "the capital of Scotland" are called definite terms and they gave no lean amount of head ache to logicians and philosophers for a long time. Russell and Quine sorted them out saying that they are not actually "referential", i.e., it is a mistake to think that the above examples are used to refer to entities. The right way to understand the above sentence is to say

Scotland has had a capital since 1999 and that capital is Edinburgh.

This sentence cannot be transformed to a nutty one. Problem solved! The point of Quine was to say that natural language is messy, or at least complicated, because it is made to be convenient for practical use, but philosophers and logicians should bring clarity by understanding them in the right way. Referential transparency is a tool to be used for bringing such clarity of meaning.

What does all this have to do with programming? Not very much, actually. As we said, referential transparency is a tool to be used in understanding language, i.e., in assigning meaning. Christopher Strachey, who founded the field of programming language semantics, used it in his study of meaning. His foundational paper "Fundamental concepts in programming languages" is available on the web. It is a beautiful paper and everybody can read and understand it. So, please do so. You will be much enlightened. He introduces the term "referential transparency" in this paragraph:

One of the most useful properties of expressions is that called by Quine [4] referential transparency. In essence this means that if we wish to find the value of an expression which contains a sub-expression, the only thing we need to know about the sub-expression is its value. Any other features of the sub-expression, such as its internal structure, the number and nature of its components, the order in which they are evaluated or the colour of the ink in which they are written, are irrelevant to the value of the main expression.

The use of "in essence" suggests that Strachey is paraphrasing it in order to explain it in simple terms. Functional programmers seem to understand this paragraph in their own way. There are 9 other occurrences of "referential transparency" in the paper, but they don't seem to bother about any of the others. In fact, the whole paper of Strachey is devoted to explaining the meaning of imperative programming languages. But, today, functional programmers claim that imperative programming languages are not referentially transparent. Strachey would be turning in his grave.

We can salvage the situation. We said that natural language is "messy, or at least complicated" because it is made to be convenient for practical use. Programming languages are the same way. They are "messy, or at least complicated" because they are made to be convenient for practical use. That does not mean that they need to confuse us. They just have to be understood the right way, using a meta language that is referentially transparent so that we have clarity of meaning. In the paper I cited, Strachey does exactly that. He explains the meaning of imperative programming languages by breaking them down into elementary concepts, never losing clarity anywhere. An important part of his analysis is to point out that variables in programming languages have two kinds of "values", called l-values and r-values. Before Strachey's paper, this was not understood and confusion reigned supreme. Today, the definition of C mentions it routinely and every C programmer understands the distinction. (Whether the programmers in other languages understand it equally well is hard to say.)

Both Quine and Strachey were concerned with the meaning of language constructions that involve some form of context-dependence. For example, our example "Edinburgh has been the capital of Scotland since 1999" signifies the fact that "capital of Scotland" depends on the time at which it is being considered. Such context-dependence is a reality, both in natural languages and programming languages. Even in functional programming, free and bound variables are to be interpreted with the respect to the context in which they appear in. Context dependence of any kind blocks referential transparency in some way or the other. If you try to understand the meaning of terms without regard to the contexts they depend on, you would again end up with confusion. Quine was concerned with the meaning of modal logic. He held that modal logic was referentially opaque and it should be cleaned up by translating it into a referentially transparent framework (e.g., by regarding necessity as provability). He largely lost this debate. Logicians and philosophers alike found Kripke's possible world semantics to be perfectly adequate. Similar situation also reigns with imperative programming. State-dependence explained by Strachey and store-dependence explained by Reynolds (in a manner similar to Kripke's possible world semantics) are perfectly adequate. Functional programmers don't know much of this research. Their ideas on referential transparency are to be taken with a large grain of salt.

[Additional note: The examples above illustrate that a simple phrase such as "capital of Scotland" has multiple levels of meaning. At one level, we might be talking about the capital at the current time. At another level, we might talking about all possible capitals that Scotland might have had through the course of time. We can "zoom into" a particular context and "zoom out" to span all contexts quite easily in normal practice. The efficiency of natural language makes use of our ability to do so. Imperative programming languages are efficient in very much the same way. We can use a variable x on the right hand side of an assignment (the r-value) to talk about its value in a particular state. Or, we might talk about its l-value which spans all states. People are rarely confused by such things. However, they may or may not be able to precisely explain all the layers of meaning inherent in language constructs. All such layers of meaning are not necessarily 'obvious' and it is a matter of science to study them properly. However, the inarticulacy of ordinary people to explain such layered meanings doesn't imply that they are confused about them.]

A separate "postscript" below relates this discussion to the concerns of functional and imperative programming.

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

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