encyclopegia.org

Total functional programming

Total functional programming (also known as strong functional programming, to be contrasted with ordinary, or weak functional programming) is a programming paradigm that restricts the range of programs to those that are provably terminating.

Total functional programming (also known as strong functional programming, to be contrasted with ordinary, or weak functional programming) is a programming paradigm that restricts the range of programs to those that are provably terminating. ==Restrictions== Termination is guaranteed by the following restrictions: A restricted form of recursion, which operates only upon 'reduced' forms of its arguments, such as Walther recursion, substructural recursion, or "strongly normalizing" as proven by abstract interpretation of code. Every function must be a total (as opposed to partial) function. That is, it must have a definition for everything inside its domain. There are several possible ways to extend commonly used partial functions such as division to be total: choosing an arbitrary result for inputs on which the function is normally undefined (such as \forall x \in \mathbb{N}. x \div 0 = 0 for division); adding another argument to specify the result for those inputs; or excluding them by use of type system features such as refinement types. These restrictions mean that total functional programming is not Turing-complete. However, the set of algorithms that can be used is still huge. For example, any algorithm for which an asymptotic upper bound can be calculated (by a program that itself only uses Walther recursion) can be trivially transformed into a provably-terminating function by using the upper bound as an extra argument decremented on each iteration or recursion. For example, quicksort is not trivially shown to be substructural recursive, but it only recurs to a maximum depth of the length of the vector (worst-case time complexity O(n 2 )). A quicksort implementation on lists (which would be rejected by a substructural recursive checker) is, using Haskell: import Data.List (partition) qsort [] = [] qsort [a] = [a] qsort (a:as) = let (lesser, greater) = partition ( To make it substructural recursive using the length of the vector as a limit, we could do: import Data.List (partition) qsort x = qsortSub x x -- minimum case qsortSub [] as = as -- shows termination -- standard qsort cases qsortSub (l:ls) [] = [] -- nonrecursive, so accepted qsortSub (l:ls) [a] = [a] -- nonrecursive, so accepted qsortSub (l:ls) (a:as) = let (lesser, greater) = partition ( Some classes of algorithms have no theoretical upper bound but do have a practical upper bound (for example, some heuristic-based algorithms can be programmed to "give up" after so many recursions, also ensuring termination). Another outcome of total functional programming is that both strict evaluation and lazy evaluation result in the same behaviour, in principle; however, one or the other may still be preferable (or even required) for performance reasons. In total functional programming, a distinction is made between data and codata—the former is finitary, while the latter is potentially infinite. Such potentially infinite data structures are used for applications such as I/O. Using codata entails the usage of such operations as corecursion. However, it is possible to do I/O in a total functional programming language (with dependent types) also without codata. Both Epigram and Charity could be considered total functional programming languages, even though they do not work in the way Turner specifies in his paper. So could programming directly in plain System F, in Martin-Löf type theory or the Calculus of Constructions. ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Total functional programming." encyclopegia.org, 2026, https://encyclopegia.org/wiki/total-functional-programming. Accessed 24 November 2026.

Chicago

"Total functional programming." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/total-functional-programming.

APA

encyclopegia.org. (2026). Total functional programming. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/total-functional-programming

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Leonidas F. Livingston

enwiki · references available

Malcolm C. Tarver

enwiki · references available

St Brendan's parish, Coolock

enwiki · references available

Marion Bethune

enwiki · references available

Phil Landrum

enwiki · references available

Maryland Route 363

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1330547620 · 0.5 · snapshot enwiki-001330547620

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.