The Potential of Total Functional Programming

A total functional programming language is a language where programs are guaranteed to terminate in a finite amount of time; that is, they will neither crash, nor run into infinite loops.

To make a total functional programming language is actually not that complex—the key to totality is what to omit rather than what to include.

The last point might sound like heresy—isn’t recursion foundational to functional programming? While it’s possible to allow limited forms of recursion, with general recursion it’s trivial to write non-terminating programs (just write a function that calls itself), so it ruins our termination guarantee. While this might sound awfully limiting , remember that we can still have foundational functions like reduce in our language—we just can’t define them inside the program itself.

What’s the point?

We have a programming language that, if it type checks, is guaranteed to terminate. Of course, there’s also the added bonus of knowing that your programs will never crash, but this is just the beginning:

Further reading


  1. See eg https://wiki.haskell.org/index.php?title=Introduction_to_IO 

  2. Note that this also prevents use of the fix-point combinator, aka the y-combinator, as these functions won’t type check! See eg https://stanford-cs242.github.io/f18/lectures/03-1-recursion.html 

  3. As with any API, there can still be ways for a malicious actor to damage the system, exfiltrate data or do other bad things. However, you could avoid this by signing all code that is to be executed by clients.