TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Total Functional Programming [pdf]

207 pointsby adgasfover 8 years ago

13 comments

wyagerover 8 years ago
I&#x27;ll give a quick TL;DR of the issues at play;<p>A program in Haskell can only crash in one way (on a hypothetical computer that doesn&#x27;t break or run out of RAM): if you write a function that doesn&#x27;t have an output for every input. You can prevent this through totality checkers such as the one presented in &quot;GADTs meet their match&quot;, which you can enable in GHC, the most popular Haskell compiler.<p>However, programs can still loop forever.<p>There are several approaches to fix this. One approach is to require recursive functions to monotonically decrease on their arguments. Languages like Idris and Agda support this. The downside is you are no longer Turing complete.<p>The approach mentioned in the paper is to make a formal distinction between finite and infinite data (data and codata), and in this way you can keep termination checking for functions on finite data, but you also get to keep Turing completeness. What you do instead of proving completeness for functions that might run forever is you prove that the function &quot;does something useful&quot; every time it recurses.
评论 #12648106 未加载
评论 #12648088 未加载
vogover 8 years ago
This is a very good explaination of that topic, creating languages which are not turing complete but still useful.<p>Also, I recommend reading Harper&#x27;s throughts about it:<p><i>&quot;Old Neglected Theorems Are Still Theorems&quot;</i> <a href="https:&#x2F;&#x2F;existentialtype.wordpress.com&#x2F;2014&#x2F;03&#x2F;20&#x2F;old-neglected-theorems-are-still-theorems&#x2F;" rel="nofollow">https:&#x2F;&#x2F;existentialtype.wordpress.com&#x2F;2014&#x2F;03&#x2F;20&#x2F;old-neglect...</a><p>It also reminds me of the NASA coding standards, rule 4:<p><i>&quot;All loops must have a fixed upper-bound&quot;</i>, see <a href="http:&#x2F;&#x2F;pixelscommander.com&#x2F;en&#x2F;javascript&#x2F;nasa-coding-standarts-for-javascript-performance&#x2F;" rel="nofollow">http:&#x2F;&#x2F;pixelscommander.com&#x2F;en&#x2F;javascript&#x2F;nasa-coding-standar...</a><p>(Related HN discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8856226" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8856226</a>)
评论 #12646651 未加载
thecity2over 8 years ago
Related to this, Idris has a totality checker. It does not require totality, however.<p><a href="http:&#x2F;&#x2F;docs.idris-lang.org&#x2F;en&#x2F;latest&#x2F;tutorial&#x2F;theorems.html#directives-and-compiler-flags-for-totality" rel="nofollow">http:&#x2F;&#x2F;docs.idris-lang.org&#x2F;en&#x2F;latest&#x2F;tutorial&#x2F;theorems.html#...</a>
murbard2over 8 years ago
The focus on &quot;totality&quot; undersells one key advantage of the restrictions in this language. You gain the ability to easily prove general properties about your program. This is <i>not</i> a consequence of totality. There are total programming languages which allow you to write programs with undecidable properties. This is really a language where properties are easy to prove, and termination happens to be one of them.<p>The topic often comes up in the discussion of smart contracts on public blockchains, and people often get confused about what Rice&#x27;s theorem says. I recently did a small write up on the topic (plug, plug)<p><a href="https:&#x2F;&#x2F;hackernoon.com&#x2F;smart-contracts-turing-completeness-reality-3eb897996621#.heipbfzgf" rel="nofollow">https:&#x2F;&#x2F;hackernoon.com&#x2F;smart-contracts-turing-completeness-r...</a>
评论 #12650506 未加载
DenisMover 8 years ago
[...] We consider a simple discipline of total functional programming designed to exclude the possibility of non-termination. [...]<p>So the idea seems to be a programming framework that on one hand guarantees termination, while on the other hand is sufficiently powerful to be useful. That is &quot;useful despite being sub-turing&quot;.<p>I spent some time causally studying the subject of sub-turing languages, and found something notable. If a language guarantees that all its programs consume input as they go, that program is guaranteed to terminate, and so the language itself is sub-turing. One example of such program could be a compiler, which makes for a great example of a useful application of a sub-turing language.<p>It&#x27;s a fascinating subject because sub-turing language programs are a lot easier to analyze.
评论 #12648224 未加载
评论 #12647374 未加载
westoncbover 8 years ago
I&#x27;m still a little unclear on what we would achieve by making the language &#x27;complete.&#x27; I get that being able to check for non-termination would be useful—but is there more?<p>The paper opens with:<p><i>The driving idea of functional programming is to make programming more closely related to mathematics.</i><p>From a paper by John Backus:<p><i>Associated with the functional style of programming is an algebra of programs whose variables range over programs and whose operations are combining forms. This algebra can be used to transform programs and to solve equations whose “unknowns” are programs in much the same way one transforms equations in high school algebra.</i><p>Are they talking about the same thing here?<p>Also, are there advantages to having such an algebra of programs outside of correctness verification?
评论 #12648261 未加载
评论 #12648932 未加载
almataover 8 years ago
Super interesting reading, thank you. Does anyone know similar papers on functional programming? I&#x27;ve sometimes found some that were much more difficult to read if you&#x27;re not a mathematician.
评论 #12648980 未加载
ht85over 8 years ago
<p><pre><code> fib (n+2) = fib (n+1) + fib (n+2) </code></pre> Something&#x27;s wrong there...
评论 #12648164 未加载
oconnor0over 8 years ago
I love this paper. The idea of non-Turing-complete languages that are quite useful for real work (whatever that means) is such a fascinating concept. Knowing at compile time that my program won&#x27;t run off in unending or unproductive code seems like such a useful bit of static checking.<p>There are also essentially no total languages today. Idris, Coq, etc. have support for totality, but there&#x27;s nothing widespread or simple that does. I expect a total language would be quite useful in certain contexts (real-time, scripting, running user code, compilers), but the drive for - I can do whatever I want in this language - is so strong that a total language would need to provide significant, useful advantages to see adoption.
评论 #12651946 未加载
评论 #12647860 未加载
评论 #12650192 未加载
评论 #12647355 未加载
snake117over 8 years ago
I was recently introduced to functional programming when I started learning Elixir. There seems to be so much potential with Elixir and I am not kidding when I say that learning the concepts of functional programming was one of the more &quot;mind bending&quot; ventures I have taken. I don&#x27;t mean this in a negative way. If anything, it opened my mind to think about problem solving&#x2F;programming in a completely different way.<p>For example, something as simple as <i>assigning</i> a variable has so much more meaning and functionality than I am used to, thanks to pattern matching.<p>I look forward to diving deeper into functional programming. Thanks for posting.
评论 #12650216 未加载
评论 #12647546 未加载
评论 #12647147 未加载
nickpsecurityover 8 years ago
The Charity language appears to fit into this mold:<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Charity_(programming_language)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Charity_(programming_language)</a><p>Very interesting stuff.
pklauslerover 8 years ago
The second paragraph of the text refers to &quot;the functional subset of Standard ML&quot;; does that mean Standard ML less reassignment of references?
swordbetaover 8 years ago
Any mirror? &quot;You have exceeded your daily download allowance&quot;
评论 #12646717 未加载
评论 #12646686 未加载