Java as a Functional Programming Language

We introduce a direct encoding of the typed λ-calculus into Java: for any Java types A, B we introduce the type A → B together with function application and λ-abstraction. The latter makes use of anonymous inner classes. We show that λ-terms are evaluated by call-by-value. We then look at how to model domain equations in Java and as an example consider the untyped lambda calculus. Then we investigate the use of function parameters in order to control overriding and in order to dynamically update methods, which can substitute certain applications of the state pattern. Further we introduce a foreach-loop in collection classes. Finally we introduce algebraic types. Elements of the resulting type are given by their elimination rules. Algebraic types with infinitely many arguments like Kleene's O and simultaneous algebraic types are already contained in that notion. Further we introduce an operation selfupdate, which allows to modify for instance a subtree of a tree, without making a copy of the original tree. All the above constructions are direct and can be done by hand.

[1]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[2]  Todd L. Veldhuizen,et al.  Expression templates , 1996 .

[3]  Matthias Felleisen,et al.  Synthesizing Object-Oriented and Functional Design to Promote Re-Use , 1998, ECOOP.

[4]  Oleg Kiselyov Functional style in C++: closures, late binding, and Lambda abstractions , 1998, ICFP '98.

[5]  A. Troelstra Metamathematical investigation of intuitionistic arithmetic and analysis , 1973 .

[6]  Martín Abadi,et al.  A Theory of Objects , 1996, Monographs in Computer Science.

[7]  Jens Palsberg,et al.  The essence of the Visitor pattern , 1998, Proceedings. The Twenty-Second Annual International Computer Software and Applications Conference (Compsac '98) (Cat. No.98CB 36241).

[8]  Glynn Winskel,et al.  The formal semantics of programming languages - an introduction , 1993, Foundation of computing series.

[9]  Henrietta Hardy Mrs Hammond The complete guide , 1883 .

[10]  Martin Odersky,et al.  Extensible algebraic datatypes with defaults , 2001, ICFP '01.

[11]  Robin Milner,et al.  Definition of standard ML , 1990 .

[12]  Richard S. Bird,et al.  Introduction to functional programming , 1988, Prentice Hall International series in computer science.

[13]  Konstantin Läufer,et al.  A Framework for Higher-Order Functions in C++ , 1995, COOTS.

[14]  Prof. Dr. Robert F. Stärk,et al.  Java and the Java Virtual Machine , 2001, Springer Berlin Heidelberg.

[15]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[16]  G. Winskel The formal semantics of programming languages , 1993 .

[17]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[18]  Richard S. Bird,et al.  Introduction to functional programming using haskeu , 1998 .

[19]  Todd L. Veldhuizen C++ Templates as Partial Evaluation , 1999, PEPM.

[20]  Chris Okasaki,et al.  Purely functional data structures , 1998 .

[21]  Gilad Bracha Adding Generics to the JavaTM Programming Language , 2001, OOPSLA 2001.

[22]  Simon Thompson,et al.  Haskell: The Craft of Functional Programming , 1996 .

[23]  Egon Börger,et al.  Java and the Java Virtual Machine: Definition, Verification, Validation , 2001 .

[24]  Douglas Gregor,et al.  C++ Templates: The Complete Guide , 2002 .

[25]  Martin Odersky,et al.  Making the future safe for the past: adding genericity to the Java programming language , 1998, OOPSLA '98.

[26]  Ulrich Berger,et al.  An inverse of the evaluation functional for typed lambda -calculus , 1991, [1991] Proceedings Sixth Annual IEEE Symposium on Logic in Computer Science.

[27]  Guy L. Steele,et al.  Java Language Specification, Second Edition: The Java Series , 2000 .

[28]  S. A. Smith,et al.  AN EXPRESSION TEMPLATE AWARE LAMBDA FUNCTION , 2000 .

[29]  P. J. Landin,et al.  The next 700 programming languages , 1966, CACM.

[30]  Atsushi Igarashi,et al.  On Inner Classes , 2002, Inf. Comput..

[31]  Martín Abadi,et al.  A Theory of Primitive Objects , 1996 .

[32]  Martín Abadi,et al.  A Theory of Primitive Objects - Untyped and First-Order Systems , 1994, TACS.

[33]  Martín Abadi,et al.  A semantics of object types , 1994, Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science.

[34]  Martin Odersky,et al.  Pizza into Java: translating theory into practice , 1997, POPL '97.