Skip to main content

Java as a Functional Programming Language

  • Conference paper
  • First Online:
Types for Proofs and Programs (TYPES 2002)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 2646))

Included in the following conference series:

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.

Supported by the Nuffield Foundation, grant No. NAL/00303/G

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. M. Abadi and L. Cardelli. A semantics of object types. In Proceedings of the 9th Symposium on Logic in Computer Science, pages 332–341, 1994.

    Google Scholar 

  2. M. Abadi and L. Cardelli. A theory of primitive objects: Untyped and first order system. Information and Computation, 125(2):78–102, 1996.

    Article  MATH  MathSciNet  Google Scholar 

  3. M. Abadi and Luca Cardelli, editors. A Theory of Objects. Springer, Berlin, Heidelberg, New York, 1996.

    MATH  Google Scholar 

  4. Ben Albahari. A comparative overview of C#. http://genamics.com/developer/csharp_comparative.htm.

  5. Gilad Bracha et al. Adding generics to the Java programming language: Participant draft specification. http://jcp.org/aboutJava/communityprocess/review/jsr014/index.html, 2001.

  6. Richard Bird. Introduction to functional programming using Haskell. Pearson Education, Harlow, second edition, 1998.

    Google Scholar 

  7. Gilad Bracha, Martin Odersky, David Stoutamire, and Philip Wadler. Making the future safe for the past: Adding genericity to the Java programming language. ACMSIGPLAN Notices, 33(10):183–200, 1998.

    Article  Google Scholar 

  8. U. Berger and H. Schwichtenberg. An inverse of the evaluation functional for typed lambda-calculus. In R. Vemuri, editor, Proceedings of the Sixth Annual IEEE Symposium on Logic in Computer Science (LICS), pages 203–211. IEEE Computer Society Press, 1991.

    Google Scholar 

  9. Mark-Jason Dominus. Pure untyped lambda-calculus and popular programming languages. J. Funct. Progr., pages 1–7, 1999.

    Google Scholar 

  10. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns. Elements of reusable object-oriented software. Addison-Wesley, 1995.

    Google Scholar 

  11. J. Gosling, B. Joy, G. Steele, and G. Brache. The Java Language Specification. Addison-Wesley, second edition, 2000.

    Google Scholar 

  12. Atsushi Igarashi and Benjamin C. Pierce. On inner classes. In European Conference on Object-Oriented Programming (ECOOP), volume 1850 of Springer Lecture Notes in Computer Science, pages 129–153, 2000.

    Google Scholar 

  13. The Java Language Team. About Microsoft’s delegates. http://java.sun.com/docs/white/delegates.html, 2002.

  14. Jaakko Järvi and Gary Powell. The lambda library. Available from http://lambda.cs.utu.fi and http://www.boost.org/libs/lambda/doc/.

  15. S. Krishnamurthi, M. Felleisen, and D. Friedman. Synthesizing object-oriented and functional design to promote re-use. In European Conference on Object-Oriented Programming, pages 91–113, 1998.

    Google Scholar 

  16. Ole Kiselyov. Functional style in c++: Closures, late binding, and lambda abstractions. A poster presentation at the 1998 International Conference on Functional Programming (ICFP’98), available from http://okmij.org/ftp/c++-digest/Functional-Cpp.html, 1998.

  17. P. J. Landin. The next 700 programming languages. Communications of the ACM, 9(3):157–164, March 1966. Originally presented at the Proceedings of the ACM Programming Language and Pragmatics Conference, August 8–12, 1965.

    Article  MATH  Google Scholar 

  18. K. Läufer. A framework for higher-order functions in C++. In Proc. Conf. Object-Oriented Technologies (COOTS). USENIX, 1995.

    Google Scholar 

  19. Microsoft Corporation. The truth about delegates. http://msdn.microsoft.com/visualj/technical/articles/delegates/truth.asp, 2002.

  20. Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. The definition of Standard ML (revised). MIT Press, Cambridge, Massachusetts and London, 1997.

    Google Scholar 

  21. Chris Okasaki. Purely functional data structures. Cambridge University Press, Cambridge, 1998.

    Google Scholar 

  22. Martin Odersky and Philip Wadler. Pizza into Java: translating theory into practice. In Conference record of POPL’ 97, pages 146–159, New York, NY 10036, USA, 1997. ACM Press.

    Google Scholar 

  23. J. Palsberg and B. Jay. The essence of the visitor pattern. In Proc. 22nd IEEE Int. Computer Software and Applications Conf, COMPSAC, pages 9–15, 1998.

    Google Scholar 

  24. J. Shoenfield. Mathematical Logic. Addison-Wesley, Reading, Massachusetts, 1967.

    MATH  Google Scholar 

  25. Jörg Striegnitz and Stephen A. Smith. An expression template aware lambda function. In Proceedings of the 2000 Workshop on C++ Template Programming, 2000. available from http://www.fz-juelich.de/zam/docs/autoren2001/striegnitz.html.

  26. R. Stärk, J. Schmid, and E. Börger. Java and the Java Virtual Machine-Definition, Verification, Validation. Springer, 2001.

    Google Scholar 

  27. Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley, third edition, 1997.

    Google Scholar 

  28. Sun Microsystems. Inner classes specification. http://java.sun.com/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc.html, 1997.

  29. Simon Thompson. Haskell. The craft of functional programming. Addison-Wesley, 1996.

    Google Scholar 

  30. A. Troelstra, editor. Metamathematical investigations of intuitionistic arithmetic and analysis, volume 344 of Springer Lecture Notes in Mathematics. Springer, Berlin, Heidelberg, New York, 1973.

    Google Scholar 

  31. Todd L. Veldhuizen. Expression templates. C++ Report, 7(5):26–31, June 1995.

    Google Scholar 

  32. Todd L. Veldhuizen. C++ templates as partial evaluation. In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Tech. Report NS-99-1, pages 13–18. BRICS, 1999.

    Google Scholar 

  33. David Vandevoorde and Nicolai M. Josuttis. C++ Templates. The complete guide. Addison-Wesley, 2003.

    Google Scholar 

  34. Glynn Winskel. The formal semantics of programming languages. MIT Press, Cambridge, Massachusetts and London, 1998.

    Google Scholar 

  35. Matthias Zenger and Martin Odersky. Extensible algebraic datatypes with defaults. In Proceedings of ICFP’ 01, SIGPLAN Notices 36(10), pages 241–252, 2001.

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2003 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Setzer, A. (2003). Java as a Functional Programming Language. In: Geuvers, H., Wiedijk, F. (eds) Types for Proofs and Programs. TYPES 2002. Lecture Notes in Computer Science, vol 2646. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-39185-1_16

Download citation

  • DOI: https://doi.org/10.1007/3-540-39185-1_16

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-14031-3

  • Online ISBN: 978-3-540-39185-2

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics