什么是"总功能编程"?
时间:2020-03-06 14:50:24 来源:igfitidea点击:
维基百科有这样的说法:
Total functional programming (also known as strong functional programming, to be contrasted with ordinary, or weak functional programming) is a programming paradigm which restricts the range of programs to those which are provably terminating.
和
These restrictions mean that total functional programming is not Turing-complete. However, the set of algorithms which can be used is still huge. For example, any algorithm which has had an asymptotic upper bound calculated for it can be trivially transformed into a provably-terminating function by using the upper bound as an extra argument which is decremented upon each iteration or recursion.
关于总功能编程的文章,还有Lambda The Ultimate Post。
直到上周,我才在邮件列表上遇到过这种情况。
我们是否还知道其他资源,参考资料或者任何示例实现?
解决方案
如果我正确理解的话,总功能编程就意味着:用总功能编程。如果我正确地记得数学课程,则"总功能"是在其整个域中定义的函数,"部分功能"是其定义中包含"漏洞"的函数。
现在,如果我们有一个函数,对于某些输入值," v"会进入无限递归或者无限循环,或者通常不会以其他方式终止,那么函数就不会为" v"定义,因此部分的,即不是全部的。
全面功能编程不允许我们编写这样的函数。所有函数始终为所有可能的输入返回结果;然后类型检查器确保是这种情况。
我的猜测是,这极大地简化了错误处理:没有任何错误。
缺点已经在报价中提到:它不是图灵完整的。例如。操作系统本质上是一个巨大的无限循环。确实,我们不希望操作系统终止,我们将此行为称为"崩溃",然后对我们的计算机大喊大叫!
慈善是保证终止的另一种语言:
http://pll.cpsc.ucalgary.ca/charity1/www/home.html
休ume是一门有4个等级的语言。最外层是图灵完成的,最内层保证终止:
http://www-fp.cs.st-andrews.ac.uk/hume/report/