<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Total_functional_programming</id>
	<title>Total functional programming - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Total_functional_programming"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Total_functional_programming&amp;action=history"/>
	<updated>2026-10-26T03:46:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Total_functional_programming&amp;diff=4809495&amp;oldid=prev</id>
		<title>imported&gt;SilkPyjamas: Adding local short description: &quot;Programming paradigm restricted to provably terminating programs&quot;, overriding Wikidata description &quot;non-Turing-complete programming paradigm restricted to provably terminating programs&quot;</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Total_functional_programming&amp;diff=4809495&amp;oldid=prev"/>
		<updated>2025-05-20T14:49:04Z</updated>

		<summary type="html">&lt;p&gt;Adding local &lt;a href=&quot;https://en.wikipedia.org/wiki/Short_description&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Short description&quot;&gt;short description&lt;/a&gt;: &amp;quot;Programming paradigm restricted to provably terminating programs&amp;quot;, overriding Wikidata description &amp;quot;non-Turing-complete programming paradigm restricted to provably terminating programs&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Programming paradigm restricted to provably terminating programs}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Total functional programming&amp;#039;&amp;#039;&amp;#039; (also known as &amp;#039;&amp;#039;&amp;#039;strong functional programming&amp;#039;&amp;#039;&amp;#039;,&amp;lt;ref&amp;gt;This term is due to: {{Cite conference|last1=Turner|first1=D.A.|author-link=David Turner (computer scientist)|title=Elementary Strong Functional Programming|conference=First International Symposium on Functional Programming Languages in Education|date=December 1995|series=Springer LNCS|volume=1022|pages=1–13}}.&amp;lt;/ref&amp;gt; to be contrasted with ordinary, or &amp;#039;&amp;#039;weak&amp;#039;&amp;#039; [[functional programming]]) is a [[computer programming|programming]] paradigm that restricts the range of programs to those that are [[Machine that always halts|provably terminating]].&amp;lt;ref name=&amp;quot;TFP&amp;quot;&amp;gt;{{Citation|last=Turner|first=D.A.|author-link=David Turner (computer scientist)|title=Total Functional Programming|journal=[[Journal of Universal Computer Science]]|volume=10|date=2004-07-28|pages=751–768|url=http://www.jucs.org/jucs_10_7/total_functional_programming|doi=10.3217/jucs-010-07-0751|issue=7}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Restrictions==&lt;br /&gt;
Termination is guaranteed by the following restrictions:&lt;br /&gt;
&lt;br /&gt;
# A restricted form of [[recursion]], which operates only upon &amp;#039;reduced&amp;#039; forms of its arguments, such as [[Walther recursion]], [[substructural recursion]], or &amp;quot;strongly normalizing&amp;quot; as proven by [[abstract interpretation]] of code.&amp;lt;ref name=&amp;quot;ETinESFP&amp;quot;&amp;gt;{{Citation|last=Turner|first=D. A.|author-link=David Turner (computer scientist)|title=Ensuring Termination in ESFP|journal=Journal of Universal Computer Science|volume=6|date=2000-04-28|pages=474–488|url=http://www.jucs.org/jucs_6_4/ensuring_termination_in_esfp|doi=10.3217/jucs-006-04-0474|issue=4}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Every function must be a total (as opposed to [[partial function|partial]]) function. That is, it must have a definition for everything inside its domain.&lt;br /&gt;
#* 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 &amp;lt;math&amp;gt;\forall x \in \mathbb{N}. x \div 0 = 0&amp;lt;/math&amp;gt; for division); adding another argument to specify the result for those inputs; or excluding them by use of type system features such as [[refinement type]]s.&amp;lt;ref name=&amp;quot;TFP&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 [[Upper bound|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.&lt;br /&gt;
&lt;br /&gt;
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 [[Big O notation|O]](&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;)). A quicksort implementation on lists (which would be rejected by a substructural recursive checker) is, using [[Haskell (programming language) | Haskell]]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;haskell&amp;quot;&amp;gt;&lt;br /&gt;
import Data.List (partition)&lt;br /&gt;
&lt;br /&gt;
qsort []       = []&lt;br /&gt;
qsort [a]      = [a]&lt;br /&gt;
qsort (a:as)   = let (lesser, greater) = partition (&amp;lt;a) as&lt;br /&gt;
                 in qsort lesser ++ [a] ++ qsort greater&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make it substructural recursive using the length of the vector as a limit, we could do:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;haskell&amp;quot;&amp;gt;&lt;br /&gt;
import Data.List (partition)&lt;br /&gt;
&lt;br /&gt;
qsort x = qsortSub x x&lt;br /&gt;
-- minimum case&lt;br /&gt;
qsortSub []     as     = as -- shows termination&lt;br /&gt;
-- standard qsort cases&lt;br /&gt;
qsortSub (l:ls) []     = [] -- nonrecursive, so accepted&lt;br /&gt;
qsortSub (l:ls) [a]    = [a] -- nonrecursive, so accepted&lt;br /&gt;
qsortSub (l:ls) (a:as) = let (lesser, greater) = partition (&amp;lt;a) as&lt;br /&gt;
                            -- recursive, but recurs on ls, which is a substructure of&lt;br /&gt;
                            -- its first input.&lt;br /&gt;
                         in qsortSub ls lesser ++ [a] ++ qsortSub ls greater&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;give up&amp;quot; after so many recursions, also ensuring termination).&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;ref&amp;gt;The differences between lazy and eager evaluation are discussed in: {{cite book|last=Granström|first=J. G.|title=Treatise on Intuitionistic Type Theory|series=Logic, Epistemology, and the Unity of Science|volume=7|year=2011|url=https://www.springer.com/philosophy/book/978-94-007-1735-0|isbn=978-94-007-1735-0}} See in particular pp. 86–91.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In total functional programming, a distinction is made between [[data]] and [[codata (computer science)|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.&amp;lt;ref&amp;gt;{{Citation|last=Granström|first=J. G.|title=A New Paradigm for Component-based Development|date=May 2012|journal=Journal of Software|volume=7|issue=5|pages=1136–1148|doi=10.4304/jsw.7.5.1136-1148}} [https://web.archive.org/web/20200709203859/http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.369.3459&amp;amp;rep=rep1&amp;amp;type=pdf Archived copy]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both [[Epigram (programming language)|Epigram]] and [[Charity (programming language)|Charity]] could be considered total functional programming languages, even though they do not work in the way [[David Turner (computer scientist)|Turner]] specifies in his paper. So could programming directly in plain [[System F]], in [[Martin-Löf type theory]] or the [[Calculus of Constructions]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Termination analysis]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Total Functional Programming}}&lt;br /&gt;
[[Category:Programming paradigms]]&lt;br /&gt;
[[Category:Functional programming]]&lt;br /&gt;
[[Category:Proof assistants]]&lt;/div&gt;</summary>
		<author><name>imported&gt;SilkPyjamas</name></author>
	</entry>
</feed>