Java as a functional programming language

  • Authors:
  • Anton Setzer

  • Affiliations:
  • Dept. of Computing Science, University of Wales Swansea, Swansea, UK

  • Venue:
  • TYPES'02 Proceedings of the 2002 international conference on Types for proofs and programs
  • Year:
  • 2002

Quantified Score

Hi-index 0.00

Visualization

Abstract

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.