什么是“自由变量”?
(我确信这个网站上一定已经回答了这个问题,但是搜索被在 C 中的变量上调用 free() 的概念淹没了。)
我遇到了术语“eta 缩减”,它的定义类似于 <代码>fx = M x ==> M 如果 x “在 M 中不自由”。我的意思是,我想我理解它想要表达的要点,这似乎就像将函数转换为无点样式时所做的那样,但我不知道关于 x 不自由的限定符意味着什么。
(I'm sure this must have been answered on this site already, but search gets inundated with the concept of calling free() on a variable in C.)
I came across the term "eta reduction," which was defined something like f x = M x ==> M
if x is "not free in M". I mean, I think I understand the gist of what it's trying to say, it seems like what you do when you convert a function to point-free style, but I don't know what the qualifier about x not being free means.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是一个示例:
在此 lambda 中,
x
是一个自由变量。基本上,自由变量是 lambda 中使用的变量,但它不是 lambda 参数之一(或let
变量)。它来自 lambda 上下文之外。Eta 减少意味着我们可以改变:
但前提是
x
在g
中不是自由的(即它没有被使用或者是一个参数)。否则我们将创建一个引用未知变量的表达式:Here's an example:
In this lambda,
x
is a free variable. Basically a free variable is a variable used in a lambda that is not one of the lambda's arguments (or alet
variable). It comes from outside the context of the lambda.Eta reduction means we can change:
But only if
x
is not free (i.e. it is not used or is an argument) ing
. Otherwise we'd be creating an expression which refers to a unknown variable:好吧,这是相关的维基百科文章,值得一看。
简而言之,此类定义使用“M”等占位符省略了 lambda 表达式的主体,因此必须另外指定由该 lambda 绑定的变量不用于占位符表示的任何内容。
因此,这里的“自由变量”大致意味着在某些不明确或未知的外部范围中定义的变量 - 例如,在像
\y -> 的表达式中。 x + y
,x
是自由变量,但y
不是。Eta 减少是指删除多余的绑定层并立即应用变量,这(正如您可能想象的那样)仅当所讨论的变量仅在该一个地方使用时才有效。
Well, here's the relevant Wikipedia article, for what that's worth.
The short version is that such definitions elide the body of a lambda expression using a placeholder like "M", and so have to specify additionally that the variable being bound by that lambda isn't used in whatever the placeholder represents.
So, a "free variable" here roughly means a variable defined in some ambiguous or unknown outer scope--e.g., in an expression like
\y -> x + y
,x
is a free variable buty
is not.Eta reduction is about removing a superfluous layer of binding and immediately applying a variable, which is (as you would probably imagine) only valid if the variable in question is only used in that one place.