什么是“自由变量”?

发布于 2024-12-26 15:58:45 字数 201 浏览 1 评论 0原文

(我确信这个网站上一定已经回答了这个问题,但是搜索被在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑梦风尘 2025-01-02 15:58:45

下面是一个示例:

\f -> f x

在此 lambda 中,x 是一个自由变量。基本上,自由变量是 lambda 中使用的变量,但它不是 lambda 参数之一(或 let 变量)。它来自 lambda 上下文之外。

Eta 减少意味着我们可以改变:

(\x -> g x) to (g)

但前提是 xg 中不是自由的(即它没有被使用或者是一个参数)。否则我们将创建一个引用未知变量的表达式:

(\x -> (x+) x) to (x+) ???

Here's an example:

\f -> f x

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 a let variable). It comes from outside the context of the lambda.

Eta reduction means we can change:

(\x -> g x) to (g)

But only if x is not free (i.e. it is not used or is an argument) in g. Otherwise we'd be creating an expression which refers to a unknown variable:

(\x -> (x+) x) to (x+) ???
半﹌身腐败 2025-01-02 15:58:45

好吧,这是相关的维基百科文章,值得一看。

简而言之,此类定义使用“M”等占位符省略了 lambda 表达式的主体,因此必须另外指定由该 lambda 绑定的变量不用于占位符表示的任何内容。

因此,这里的“自由变量”大致意味着在某些不明确或未知的外部范围中定义的变量 - 例如,在像 \y -> 的表达式中。 x + yx 是自由变量,但 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 but y 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文