Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/325694.325709acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
Article
Free access

A new approach to generic functional programming

Published: 05 January 2000 Publication History
  • Get Citation Alerts
  • Abstract

    This paper describes a new approach to generic functional programming, which allows us to define functions generically for all datatypes expressible in Haskell. A generic function is one that is defined by induction on the structure of types. Typical examples include pretty printers, parsers, and comparison functions. The advanced type system of Haskell presents a real challenge: datatypes may be parameterized not only by types but also by type constructors, type definitions may involve mutual recursion, and recursive calls of type constructors can be arbitrarily nested. We show that—despite this complexity—a generic function is uniquely defined by giving cases for primitive types and type constructors (such as disjoint unions and cartesian products). Given this information a generic function can be specialized to arbitrary Haskell datatypes. The key idea of the approach is to model types by terms of the simply typed λ-calculus augmented by a family of recursion operators. While conceptually simple, our approach places high demands on the type system: it requires polymorphic recursion, rank-n types, and a strong form of type constructor polymorphism. Finally, we point out connections to Haskell's class system and show that our approach generalizes type classes in some respects.

    References

    [1]
    M. Abadi, L. Cardelli, B. Pierce, and D. R~my. Dynamic typing in polymorphic languages. Journal of Functional Programming, 5(1):111-130, January 1995.]]
    [2]
    H. P. Barendregt. The Lambda Calculus m Its Syntax and Semantics. North-Holland, Amsterdam New York Oxford, revised edition, 1984.]]
    [3]
    H.P. Barendregt. Lambda calculi with types. In S. Abramsky, Dov M. Gabbay, and T.S.E. Maibaum, editors, Handbook of Logic in Computer Science, Volume 2, Background: Computational Structures, pages 118-309. Clarendon Press, Oxford, 1992.]]
    [4]
    Richard Bird. Introduction to Functional Programming using Haskell. Prentice Hall Europe, London, 2nd edition, 1998.]]
    [5]
    Richard Bird and Lambert Meertens. Nested datatypes. In J. Jeuring, editor, Fourth International Conference on Mathematics of Program Construction, MPC'98, Marstrand, Sweden, volume 1422 of Lecture Notes in Computer Science, pages 52-67. Springer- Verlag, June 1998.]]
    [6]
    Richard Bird and Ross Paterson. De Bruijn notation as a nested datatype. Journal of Functional Programming, 9(1):77-91, January 1999.]]
    [7]
    Richard Bird and Ross Paterson. Generalised folds for nested datatypes. Formal Aspects o} Computing, 11(2):200-222, 1999.]]
    [8]
    Robin Cockett and Tom Fukushima. About Charity. Yellow Series Report 92/480/18, Dept. of Computer Science, Univ. of Calgary, June 1992.]]
    [9]
    Bruno Courcelle. Fundamental properties of infinite trees. Theoretical Computer Science, 25(2):95-169, March 1983.]]
    [10]
    Karl Crary, Stephanie Weirich, and Greg Morrisett. Intensional polymorphism in type-erasure semantics. ACM SIGPLAN Notices, 34(1):301-312, 1999.]]
    [11]
    Jean-Yves Girard. Interpretation fonctionelle et dlimination des coupures dans l'ar~thdtique d'ordre supdrieur. PhD thesis, Universit~ Paris VII, 1972.]]
    [12]
    T. Hagino. Category Theoretic Approach to Data Types. PhD thesis, University of Edinburgh, 1987.]]
    [13]
    Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. Type classes in Haskell. A CM Transactions on Programming Languages and Systems, 18(2):109-138, March 1996.]]
    [14]
    Robert Harper and Greg Morrisett. Compiling polymorphism using intensional type analysis. In ACM, editor, Conference record of the 22nd A CM SIGPLAN- SIGACT Symposium on Principles of Programming Languages, POPL '95, San Francisco, California, pages 130-141. ACM-Press, 1995.]]
    [15]
    Ralf Hinze. Numerical representations as higher-order nested datatypes. Technical Report IAI-TR-98-12, Institut fiir Informatik III, Universit~t Bonn, December 1998.]]
    [16]
    Ralf Hinze. Generalizing generalized tries. Journal of Functional Programming, 1999. Accepted for publication.]]
    [17]
    Ralf Hinze. A generic programming extension for Haskell. In Erik Meijer, editor, Proceedings of the 3rd Haskelt Workshop, Paris, France, September 1999. The proceedings appear as a technical report of Universiteit Utrecht, UU-CS-1999-28.]]
    [18]
    Ralf Hinze. Manufacturing datatypes. In Chris Okasaki, editor, Proceedings of the Workshop on Algorithmic Aspects of Advanced Programming Languages, WAAAPL'99, Paris, France, pages 1-16, September 1999. The proceedings appear as a technical report of Columbia University, CUCS-023-99, also available from http ://www. cs. columbia, edu/~ cdo/waaapl, html.]]
    [19]
    Ralf Hinze. Polytypic functions over nested datatypes. Discrete Mathematics and Theoretical Computer Science, 3(4):159-180, 1999.]]
    [20]
    Ralf Hinze. Polytypic programming with ease (extended abstract). In $th Fuji International Symposium on Functional and Logic Programming (FLOPS'99), Tsukuba, Japan, Lecture Notes in Computer Science. Springer-Verlag, November 1999. To appear.]]
    [21]
    Patrik Jansson and Johan 3euring. PolyP--a polytypic programming language extension. In Conference Record P~th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL'97, Paris, France, pages 470-482. ACM-Press, January 1997.]]
    [22]
    Patrik Jansson and Johan Jeuring. PolyLib--A library of polytypic functions. In Roland Backhouse and Tim Sheard, editors, Informal Proceedings Workshop on Generic Programming, WGP'98, Marstrand, Sweden. Department of Computing Science, Chalmers University of Technology and GSteborg University, June 1998.]]
    [23]
    Patrik Jansson and 3ohan Jeuring. Polytypic compact printing and parsing. In S. Doaitse Swierstra, editor, Proceedings European Symposium on Programming, ESOP'99, volume 1576 of Lecture Notes in Computer Science, pages 273-287, Berlin, 1999. Springer- Verlag.]]
    [24]
    C.B. Jay, G. Bellb, and E. Moggi. Functorial ML. Journal of Functional Programming, 8(6):573-619, November 1998.]]
    [25]
    C.B. Jay and J.R.B. Cocker. Shapely types and shape polymorphism. In D. Sanella, editor, Programming Languages and Systems ~ ESOP'9~: 5th European Symposium on Programming, Edinburgh, UK, Proceedings, volume 788 of Lecture Notes in Computer Science, pages 302-316, Berlin, 11-13 April 1994. Springer* Verlag.]]
    [26]
    Johan Jeuring and Patrik Jansson. Polytypic programming. In J. Launchbury, E. Meijer, and T. Sheaxd, editors, Tutorial Text 2nd International School on Advanced Functional Programming, Olympia, WA, USA, volume 1129 of Lecture Notes in Computer Science, pages 68-114. Springer-Verlag, 1996.]]
    [27]
    Mark P. Jones. A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of Functional Programming, 5(1):1-35, January 1995.]]
    [28]
    Mark P. Jones. Functional programming with overloadlag and higher-order polymorphism. In First International Spring School on Advanced Functional Programrain9 Techniques, volume 925 of Lecture Notes in Computer Science, pages 97-136. Springer-Verlag, 1995.]]
    [29]
    M.P. Jones and J.C. Peterson. Hugs 98 User Manual, May 1999. Available from http://www, haskell, org/ hugs.]]
    [30]
    Nancy Jean McOracken. The typechecking of programs with implicit type structure. In Gilles Kahn, David B. MacQueen, and Gordon D. Plotkin, editors, Semantics of Data Types: International Symposium, Sophia- Antipolis, France, volume 173 of Lecture Notes in Computer Science, pages 301-315. Springer-Verlag, 1984.]]
    [31]
    Lambert Meertens. Calculate polytypically! In H. Kuchen and S.D. Swierstra, editors, Proceedings 8th International Symposium on Programming Languages: Implementations, Logics, and Programs, PLILP'96, Aachen, Germany, volume 1140 of Lecture Notes in Computer Science, pages 1-16. Springer-Verlag, September 1996.]]
    [32]
    Erik Meijer and Grahaxn Hutton. Bananas in space: Extending fold and unfold to exponential types. In Conference Record 7th A CM SIGPLAN/SIGARUH and IFIP WG 2.8 International Conference on Functional Programming Languages and Computer Architecture, FPCA '95, La Jolla, San Diego, CA, USA, pages 324-333. ACM-Press, June 1995.]]
    [33]
    Alan Mycroft. Polymorphic type schemes and recursive definitions, in M. Paul and B. Robinet, editors, Proceedings of the International Symposium on Programming, 6th Colloquium, Toulouse, France, volume 167 of Lecture Notes in Computer Science, pages 217-228, 1984.]]
    [34]
    Chris Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998.]]
    [35]
    Chris Okasaki. From fast exponentiation to square matrices: An adventure in types. In Peter Lee, editor, Proceedings of the 1999 A CM SIGPLAN International Conference on Functional Programming, "Paris, France, pages 28-35, September 1999.]]
    [36]
    Simon Peyton Jones. Explicit quantification in Haskell, 1998. Available from http://research.microsoft. com/Us ers / s imonp j/Haske ii / quant if i cat i on. html.]]
    [37]
    Simon Peyton Jones and John Hughes, editors. Haskell 98 -- A Non-strict, Purely Functional Language, February 1999. Available from http://www, haskell, org/definition/.]]
    [38]
    Simon L. Peyton Jones. Compiling Haskell by program transformation: A report from the trenches. In Hanne Riis Nielson, editor, Programming Languages and Systems--ESOP'96, 6th European Symposium on Programming, Link6ping, Sweden, 22-2~ April, volume 1058 of Lecture Notes in Computer Science, pages 18- 44. Springer-Verlag, 1996.]]
    [39]
    Simon L. Peyton Jones and Erik Meijer. Henk: A typed intermediate language. In Proceedings of the Types in Compilation Workshop, Amsterdam, june, 1997. Available from http://~w, cs. be. edu/"muller/TIC97/.]]
    [40]
    Fritz Ruehr. Structural polymorphism. In Roland Backhouse and Tim Sheaxd, editors, Informal Proceedings Workshop on Generic Programming, WGP'98, Marstrand, Sweden, 18 June 1998. Dept. of Computing Science, Chalmers Univ. of Techn. and GSteborg Univ., June 1998.]]
    [41]
    Karl Fritz l%uehr. Analytical and Structural Polymorphism Expressed using Patterns over Types. PhD thesis, University of Michigan, 1992.]]
    [42]
    Tim Sheard. Automatic generation and use of abstract structure operators. A CM Transactions on Programming Languages and Systems, 13(4):531-557, October 1991.]]
    [43]
    Tim Sheard. Type parametric programming. Technical report CS/E 93-018, Oregon Graduate Institute of Science and Technology, Department of Computer Science and Engineering, Portland, OR, USA, November 1993.]]
    [44]
    Philip Wadler. Theorems for free! In The Fourth International Conference on Functional Programming Languages and Computer Architecture (FPCA '89), London, UK, pages 347-359. Addison-Wesley Publishing Company, September 1989.]]
    [45]
    Zhe Yang. Encoding types in ML-like languages. SIC- PLAN Notices, 34(1):289-300, January 1999.]]

    Cited By

    View all
    • (2023)Could Tierless Languages Reduce IoT Development Grief?ACM Transactions on Internet of Things10.1145/35729014:1(1-35)Online publication date: 23-Feb-2023
    • (2021)Deriving Distributive Laws for Graded Linear TypesElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.353.6353(109-131)Online publication date: 30-Dec-2021
    • (2021)LambdaKube - A Functional Programming Approach in a Distributed RealmProceedings of the 2021 4th International Conference on Geoinformatics and Data Analysis10.1145/3465222.3465233(67-72)Online publication date: 14-Apr-2021
    • Show More Cited By

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    POPL '00: Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
    January 2000
    402 pages
    ISBN:1581131259
    DOI:10.1145/325694
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

    Sponsors

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 05 January 2000

    Permissions

    Request permissions for this article.

    Check for updates

    Qualifiers

    • Article

    Conference

    POPL00

    Acceptance Rates

    POPL '00 Paper Acceptance Rate 30 of 151 submissions, 20%;
    Overall Acceptance Rate 824 of 4,130 submissions, 20%

    Upcoming Conference

    POPL '25

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)141
    • Downloads (Last 6 weeks)13
    Reflects downloads up to 10 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2023)Could Tierless Languages Reduce IoT Development Grief?ACM Transactions on Internet of Things10.1145/35729014:1(1-35)Online publication date: 23-Feb-2023
    • (2021)Deriving Distributive Laws for Graded Linear TypesElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.353.6353(109-131)Online publication date: 30-Dec-2021
    • (2021)LambdaKube - A Functional Programming Approach in a Distributed RealmProceedings of the 2021 4th International Conference on Geoinformatics and Data Analysis10.1145/3465222.3465233(67-72)Online publication date: 14-Apr-2021
    • (2019)Generic level polymorphic n-ary functionsProceedings of the 4th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3331554.3342604(14-26)Online publication date: 18-Aug-2019
    • (2018)Generic programming of all kindsACM SIGPLAN Notices10.1145/3299711.324274553:7(41-54)Online publication date: 17-Sep-2018
    • (2018)Generic programming of all kindsProceedings of the 11th ACM SIGPLAN International Symposium on Haskell10.1145/3242744.3242745(41-54)Online publication date: 17-Sep-2018
    • (2018)Generic deriving of generic traversalsProceedings of the ACM on Programming Languages10.1145/32367802:ICFP(1-30)Online publication date: 30-Jul-2018
    • (2018)Maintaining Separation of Concerns Through Task Oriented Software DevelopmentTrends in Functional Programming10.1007/978-3-319-89719-6_2(19-38)Online publication date: 19-Apr-2018
    • (2017)A Distributed Dynamic Architecture for Task Oriented ProgrammingProceedings of the 29th Symposium on the Implementation and Application of Functional Programming Languages10.1145/3205368.3205375(1-12)Online publication date: 30-Aug-2017
    • (2015)Approximate by thinningScience of Computer Programming10.1016/j.scico.2014.07.00198:P4(484-515)Online publication date: 1-Feb-2015
    • Show More Cited By

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media