Programming in the λ-Calculus: From Church to Scott and Back
Although the λ-calculus is well known as a universal programming language, it is seldom used for actual programming or expressing algorithms. Here we demonstrate that it is possible to use the λ-calculus as a comprehensive formalism for programming by showing how to convert programs written in functional programming languages like Clean and Haskell to closed λ-expressions. The transformation is based on using the Scott-encoding for Algebraic Data Types instead of the more common Church encoding. In this way we not only obtain an encoding that is better comprehensible but that is also more efficient. As a proof of the pudding we provide an implementation of Eratosthenes’ prime sieve algorithm as a self-contained, 143 character length, λ-expression.
KeywordsPattern Match Recursive Function Functional Programming Lambda Calculus Fold Function
Unable to display preview. Download preview PDF.
- 1.Barendregt, H.: The lambda calculus, its syntax and semantics, revised edition. Studies in Logic, vol. 103. North-Holland (1984)Google Scholar
- 3.Burstall, R.M., MacQueen, D.B., Sannella, D.T.: Hope: An experimental applicative language (1980)Google Scholar
- 4.Curry, H., Hindley, J., Seldin, J.: Combinatory Logic, vol. 2. North-Holland Publishing Company (1972)Google Scholar
- 6.Jansen, J., Koopman, P., Plasmeijer, R.: Efficient interpretation by transforming data types and patterns to functions. In: Nilsson, H. (ed.) Revised Selected Papers of the 7th Trends in Functional Programming 2006, vol. 7, pp. 73–90. Intellect Books, Nottingham (2006)Google Scholar
- 10.Stump, A.: Directly reflective meta-programming. Journal of Higher Order and Symbolic Computation (2008)Google Scholar
- 11.Tromp, J.: John’s lambda calculus and combinatory logic playground (2012), http://homepages.cwi.nl/~tromp/cl/cl.html
- 12.Turner, D.: Some History of Functional Programming Languages. In: Invited talk, Trends in Functional Programming 2012, TFP 2012, St. Andrews, United Kingdom (2012)Google Scholar