首页 > 解决方案 > 函数式编程中安全、纯粹和引用透明度之间的关系是什么?

问题描述

  1. pure / impure:当我们谈论 Haskell 和 lisp-family 之间的区别时出现。
  2. safe / unsafe:当我们命名 unsafePerformIO、unsafeCoerce 等函数时出现。
  3. 引用透明/引用不透明:当我们强调纯函数式编程的好处时出现。

这些词之间的区别非常微妙,我发现有一些帖子单独谈论它们,但我仍然希望它们之间有一个明确的比较,我在这里还找不到这样的帖子。

标签: haskellfunctional-programmingpurely-functional

解决方案


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.


推荐阅读