且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SML中绑定的价值?

更新时间:2022-10-21 09:01:53

What you are seeing is sometimes called lexical scoping. The function f was defined in the scope of a certain binding for x, that scope is the only scope that matters in understanding what f does when f is invoked. The fact that x has a different meaning in the scope in which f is invoked doesn't affect the meaning of f itself. In the context of functional programming anything else would violate referential transparency. In the scope of a binding such as

val x = 1

it should be possible to freely replace x by 1. Thus your definition of f should be equivalent to the definition:

def f y = 1 + y

as, indeed, it is.

相关阅读

技术问答最新文章