haskell - 函数式编程中安全、纯粹和引用透明度之间的关系是什么?
问题描述
- pure / impure:当我们谈论 Haskell 和 lisp-family 之间的区别时出现。
- safe / unsafe:当我们命名 unsafePerformIO、unsafeCoerce 等函数时出现。
- 引用透明/引用不透明:当我们强调纯函数式编程的好处时出现。
这些词之间的区别非常微妙,我发现有一些帖子单独谈论它们,但我仍然希望它们之间有一个明确的比较,我在这里还找不到这样的帖子。
解决方案
I've always been fond of Amr Sabry's 1998 paper that explored a similar question with the rigor it deserved: https://www.cs.indiana.edu/~sabry/papers/purelyFunctional.ps
A sample quote:
A language is purely functional if (i) it includes every simply typed lambda-calculus term, and (ii) its call-by-name, call-by-need, and call-by-value implementations are equivalent modulo divergence and errors.
While this question can generate a lot of "opinion" based answers (which I am carefully avoiding!), reading through Amr's paper can put you in the right mindset about how to think about this question; regardless whether you end up agreeing with him or not.
推荐阅读
- python-3.x - 如何使用漂亮的汤解析大 XML 文件?
- c - CMake 命令查询 (add_custom_command)
- r - 当未绘制二次项中的变量时,如何将 lm() 与 poly() 和 ggeffect() 一起使用来绘制模型效果
- javascript - 如何将东西存储在异步存储中?
- c - Cython 中的方法如何在 C 中实现?
- docker - Docker Desktop 无法切换到 Windows 容器
- java - 带有自定义 HTTP 错误响应的自定义 ConstraintValidator 消息
- javascript - 如何使用 Node.js 随机化 JavaScript 对象中的单个值
- javascript - 如何在 DataTable().row.add() 之后继续自定义 dataTable?
- python - 在字典中自动增加相同的值