参照透明度 [英] Referential Transparency

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

问题描述

当在功能性程序设计中使用术语引用透明时,术语不可观察的含义是什么?

解决方案

正如你可能知道的那样,术语引用透明意味着表达式的值只能取决于其部分的,而不取决于关于它们的任何其他事实。例如,它不能依赖于以下内容:


  • 表达式的某些部分已经被评估过了(用懒惰的语言)

  • 是否共享两个相等的值(指向内存中相同位置的指针)或不是
  • 数据结构是循环的(即它的指针创建一个循环)还是不是


所有关于程序当前状态的事实是真的还是假的,但没有表达式可以根据它们改变它的值。所以这些东西叫做不可观察的



这个webcomic 它的讨论在reddit上可能会启发你。


What is the meaning of the term "Non-observable" when used in context with the term "referentially transparent" in functional programming?

解决方案

As you might know, the term "referentially transparent" means that the value of expression can depend only on the values of its parts, and not on any other facts about them.

For example, it cannot depend on the following:

  • Whether some part of expression is already evaluated or not (in a lazy language)
  • Whether two equal values are shared (are pointers to the same location in memory) or not
  • Whether a data structure is cyclic (i.e. its pointers create a cycle) or not

All those facts about the current state of the program are either true or false, but no expression can change its value depending on them. So those things are called non-observable.

This webcomic and its discussion on reddit might enlighten you as well.

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

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