为什么“纯”称为“纯”的函数? [英] Why are "pure" functions called "pure"?

查看:122
本文介绍了为什么“纯”称为“纯”的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

纯函数是没有副作用的函数 - 它不能做任何类型的I / O,它不能修改任何事物的状态 - 而且它是引用透明的 - 当用相同的输入多次调用时,它总是给出相同的输出。



为什么用纯这个词来描述具有这些属性的函数?谁首先以这种方式使用纯这个词,什么时候?还有其他的词意味着大致相同的事情吗?

纯粹就某些指定变量而言。例如:


第一项是纯函数 x ,第二项是纯函数 y


因此,我认为您不会发现真正的第一事件。

对于编程语言,稍加搜索就会发现 Ada 95 pragma Pure ),高性能Fortran (1993)( PURE )和 VHDL-93 pure )都包含纯函数的形式概念'。

Haskell(1990)相当明显,但纯度并不明确。 GCC的C具有各种功能属性,适用于各种不同级别的纯。



几本书: (1990)使用了 编程语言及其定义 (1984)。但是,两者显然只使用它一次!编程IBM个人计算机,Pascal(也是1984年)使用这个术语,但从Google的限制视角来看,并不清楚Pascal编译器是否支持它。 (我怀疑不是。)



有趣的是,Ada的前身Green,实际上有一个相当严格的'函数'定义 - 即使内存分配也是不允许的。然而,它在成为Ada之前就被抛弃了,它的功能可能有副作用(I / O或全局变量),但不能修改它们的参数。

a href =http://www.bitsavers.org/pdf/ibm/360/pli/C28-6571-3_PL_I_Language_Specifications_Jul66.pdf> C28-6571-3 (第一张PL / I参考手册,在编译器之前编写)显示PL / I支持纯函数,形式为 REDUCIBLE (= pure)属性,如1966年 - 编译器首次发布时。 (这也回答你的第三个问题。)



最后一个文件特别指出它包含 REDUCIBLE 作为新变化自文件C28-6571-2。所以 REDUCIBLE ,这可能是编程语言中第一批正式纯函数的化身,出现在1966年1月至7月之间。



更新:在这个意义上,Google Groups上最早的纯功能实例是从1988年开始的,这很容易推迟书中的参考。


A pure function is one that has no side effects -- it cannot do any kind of I/O and it cannot modify the state of anything -- and it is referentially transparent -- when called multiple times with the same inputs, it always gives the same outputs.

Why is the word "pure" used to describe functions with those properties? Who first used the word "pure" in that way, and when? Are there other words that mean roughly the same thing?

解决方案

To answer your first question, mathematical functions have often been described as "pure" in terms of some specified variables. e.g.:

the first term is a pure function of x and the second term is a pure function of y

Because of this, I don't think you'll find a true "first" occurrence.

For programming languages, a little searching shows that Ada 95 (pragma Pure), High Performance Fortran (1993) (PURE) and VHDL-93 (pure) all contain formal notions of 'pure functions'.

Haskell (1990) is fairly obvious, but purity isn't explicit. GCC's C has various function attributes for various differing levels of 'pure'.

A couple of books: Rationale for the C programming language (1990) uses the term, as does Programming Languages and their Definitions (1984). However, both apparently only use it once! Programming the IBM Personal Computer, Pascal (also 1984) uses the term, but it isn't clear from Google's restricted view whether or not the Pascal compiler had support for it. (I suspect not.)

An interesting note is that Green, the predecessor to Ada, actually had a fairly strict 'function' definition - even memory allocation was disallowed. However, this was dropped before it became Ada, where functions can have side-effects (I/O or global variables), but can't modify their arguments.

C28-6571-3 (the first PL/I reference manual, written before the compiler) shows that PL/I had support for pure functions, in the form of the REDUCIBLE (= pure) attribute, as far back as 1966 - when the compiler was first released. (This also answers your third question.)

This last document specifically notes that it includes REDUCIBLE as a new change since document C28-6571-2. So REDUCIBLE, which is possibly the first incarnation of formal pure functions in programming languages, appeared somewhere between January and July 1966.

Update: The earliest instance of "pure function" on Google Groups in this sense is from 1988, which easily postdates the book references.

这篇关于为什么“纯”称为“纯”的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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