skip to main content
10.1145/289423.289458acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
Article
Free Access

Encoding types in ML-like languages

Authors Info & Claims
Published:29 September 1998Publication History

ABSTRACT

A Hindley-Milner type system such as ML's seems to prohibit type-indexed values, i.e., functions that map a family of types to a family of values. Such functions generally perform case analysis on the input types and return values of possibly different types. The goal of our work is to demonstrate how to program with type-indexed values within a Hindley-Milner type system.Our first approach is to interpret an input type as its corresponding value, recursively. This solution is type-safe, in the sense that the ML type system statically prevents any mismatch between the input type and function arguments that depend on this type.Such specific type interpretations, however, prevent us from combining different type-indexed values that share the same type. To meet this objection, we focus on finding a value-independent type encoding that can be shared by different functions. We propose and compare two solutions. One requires first-class and higher-order polymorphism, and, thus, is not implementable in the core language of ML, but it can be programmed using higher-order functors in Standard ML of New Jersey. Its usage, however, is clumsy. The other approach uses embedding/projection functions. It appears to be more practical.We demonstrate the usefulness of type-indexed values through examples including type-directed partial evaluation, C printf-like formatting, and subtype coercions. Finally, we discuss the tradeoffs between our approach and some other solutions based on more expressive typing disciplines.

References

  1. 1.Martin Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically typed language. A CM Transactions on Programming Language.s and Systems, t3(2):237-268., April 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 2.Martin Abadi, Luca Cardelli, Benjamin Pierce, and Didiet R~m,~. Dynamic typing in polymorphic languages. J o'w.,nal ofFunctional Programming, 5(1): 111-130, Janu ary 1995Google ScholarGoogle Scholar
  3. 3.Andrew W. Appel and David B. MacQueen. Standard ML of New Jersey. In Jan Maluszyfiski and Martin Wirsing, editors, Third International Symposium on Programming Language Implementation and Logic Programming, number 528 in Lecture Notes in Computer Science, pages 1-13, Passau, Germany, August 1991. Springer-Verlag.Google ScholarGoogle Scholar
  4. 4.William Clinger and Jonathan Rees, editors. Revised4 report on the algorithmic language Scheme. LISP Pointers, IV(3):1-55, July-September 199t. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 5.Olivier Danvy. Type-directed partial evaluation. In Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 6.Olivier Danvy. Formatting strings in ML. Research Series RS-98-5, BRICS, Department of Computer Science, University of Aarhus, March 1998. To appear in the Journal of Functional Programming.Google ScholarGoogle Scholar
  7. 7.Olivier Danvy. A simple solution to type specialization. Research Series RS-98-1, BRICS, Department of Computer Science, University of Aarhus, January 1998. To appear in the Proceedings of the ~5th International Colloquium on Automata, Languages, and Programming. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 8.Olivier Danvy and Peter Dybjer, editors. Preliminary Proceedings of the 1998 A PPSEM Workshop on Normalization by Evaluation, NBE '98, (GSteborg, Sweden, May 8-9, 1998), number NS-98-1 in BRICS Notes Series, BRICS, Department of Computer Science, University of Aarhus, May 1998.Google ScholarGoogle Scholar
  9. 9.Rowan Davies and Frank Pfenning. A modal analysis of staged computation. In Steele {29}, pages 258-283. Google ScholarGoogle Scholar
  10. 10.Jean-Yves Girard. The system F of variable types, fifteen years later. Theoretical Computer Science, 45(2):159-192, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 11.Cordelia Hall, Kevin Hammond, Simon Peyton-Jones, and Philip Wadler. Type classes in Haskell. A CM Transactions on Programming Languages and Systems, 18(2):109-138, March 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 12.Robert Harper and Greg Morrisett. Compiling polymorphism using intensional type analysis. In Peter Lee, editor, Proceedings of the Twenty-Second Annual A CM Symposium on Principles of Programming Lan. guages, pages 130-141, San Francisco, California, January 1995. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 13.Fritz Henglein. Dynamic typing: syntax and proof theory. Science of Computer Programming, 22(3):197-230, June 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 14.J. Roger Hindley. The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society, 146:29-60, 1969.Google ScholarGoogle Scholar
  15. 15.Mark P. Jones. A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of Functional Programming, 5(1):1-35, January 1995. An earlier version appeared in FPCA '93. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 16.Mark P. Jones. First-class polymorphism with type inference. In Jones {17}, pages 483-496. Google ScholarGoogle Scholar
  17. 17.Nell D. Jones, editor. Proceedings of the Twenty. Fourth Annual A CM Symposium on Principles of Programming Languages, Paris, France, January 1997. ACM Press.Google ScholarGoogle Scholar
  18. 18.Nell D. L ones, Carsten K. Gomard, and Peter Sestoft. Pa'c~ial Evaluation and Automatic Program Generation. Prentice Hall International, International Series in Computer Science, June 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. 19.Andrew Kennedy. Relational parametricity and units of measure. In Jones {17}, pages 442-455. Google ScholarGoogle Scholar
  20. 20.Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17:348-375, December 1978.Google ScholarGoogle ScholarCross RefCross Ref
  21. 21.Robin Milner, Mads Torte, Robert Harper, and David MacQuee:,. The Definition of Standard ML (Revised). The MIT Press, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 22.John C. Mitchell. Coercion and type inference. In Ken Kennedy, editor, Proceedings of the Eleventh Annual A CM Symposium on Principles of Programming Languages, pages 175-185, Salt Lake City, Utah, January 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 23.Martin Odersky and Konstantin L~ufer. Putting type annotations to work. In Steele {29}, pages 54-67. Google ScholarGoogle Scholar
  24. 24.John Peterson, Kevin Hammond, et al. Report on the programming language Haskell, a non-strict purelyfunction.m programming language, version 1.4. Available at the Haskell homepage: http://www.haskell.org, April 1997.Google ScholarGoogle Scholar
  25. 25.John C. Reynolds. Towards a theory of type structure. In Programming Symposium, number 19 in Lecture Notes in Computer Science, pages 408-425, Paris, France, April 1974. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. 26.Morten Rhiger. A study in higher-order programming languages. Master's thesis, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark, December 1997.Google ScholarGoogle Scholar
  27. 27.Kristoffe~ Fcose. Type-directed partial evaluation in a pure filncdonal language. In Danvy and Dybjer {8}.Google ScholarGoogle Scholar
  28. 28.Mark Shields, Tim Sheard, and Simon Peyton Jones. Dynamic wping as staged type inference. In Luca Cardetl}, editor, Proceedings of the Twenty. Fifth Annual A 6L~4 Symposium on Principles of Programming Languages, pages 289-302, San Diego, California, January 1998. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 29.Guy L. Steele, editor. Proceedings of the Twenty. Third Annual /! CM Symposium on Principles of Programruing Languages, St. Petersburg Beach, Florida, January 199~ ACM Press.Google ScholarGoogle Scholar
  30. 30.Walid Taha and Tim Sheard. Multi-stage programming. In Mads Torte, editor, Proceedings of the 1997 A CM SIOPLAN International Conference on P~nctional Programming, pages 321-321, Amsterdam, The Netherlands, June 1997. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. 31.Mads Torte. Principal signatures for higher-order program modules. Journal of Functional Programming, 4(3):285-.335, July 1994.Google ScholarGoogle Scholar
  32. 32.R.en6 V~tergaard. From proof normalization to compiler generation and type-directed change-ofrepresentation. Master's thesis, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark, May 1997.Google ScholarGoogle Scholar

Index Terms

  1. Encoding types in ML-like languages

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Conferences
        ICFP '98: Proceedings of the third ACM SIGPLAN international conference on Functional programming
        September 1998
        351 pages
        ISBN:1581130244
        DOI:10.1145/289423

        Copyright © 1998 ACM

        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]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 29 September 1998

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • Article

        Acceptance Rates

        ICFP '98 Paper Acceptance Rate30of77submissions,39%Overall Acceptance Rate333of1,064submissions,31%

        Upcoming Conference

        ICFP '24

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader