What is “Total Functional Programming”?

后端 未结 3 1441
南笙
南笙 2021-02-01 06:52

Wikipedia has this to say:

Total functional programming (also known as strong functional programming, to be contrasted with ordinary, or weak functi

3条回答
  •  广开言路
    2021-02-01 07:28

    While this is an old question, I think that none of the answers so far mention the real motivation for total functional programming, which is this:

    If programs are proofs, and proofs are programs, then programs which have 'holes' don't make any sense as proofs, and introduce logical inconsistency.

    Basically, if a proof is a program, an infinite loop can be used to prove anything. This is really bad, and provides much of the motivation for why we might want to program totally. Other answers tend to not account for the flip side of the paper. While the languages are techincally not turing complete, you can recover a lot of interesting programs by using co-inductive definitions and functions. We're very prone to think of inductive data, but codata serves an important purpose in these languages, where you can totally define a definition which is infinite (and when doing real computation which terminates, you will potentially use only a finite piece of this, or maybe not if you're writing an operating system!).

    It is also of note that most proof assistants work based on this principle, Coq, for example.

提交回复
热议问题