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

Type-safe cast: (functional pearl)

Published:01 September 2000Publication History

ABSTRACT

In a language with non-parametric or ad-hoc polymorphism, it is possible to determine the identity of a type variable at run-time. With this facility, we can write a function to convert a term from one abstract type to another, if the two hidden types are identical. However, the naive implementation of this function requires that the term be destructed and rebuilt. In this paper, we show how to eliminate this overhead using higher-order type abstraction. We demonstrate this solution in two frameworks for ad-hoc polymorphism: intensional type analysis and type classes.

References

  1. 1.M. Abadi, L. Cardelli, B. Pierce, and G. Plotkin. Dynamic typing in a statically-typed language. ACM Transactions on Programming Languages and Systems, 13(2):237-268, April 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 2.K. Crary, S.Weirich, and G. Morrisett. Intensional polymorphism in type-erasure semantics. In 1998 ACM International Conference onFunctional Programming, pages 301-312, Baltimore, Sept. 1998. Extended version published as Cornell University technical report TR98-1721. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 3.C. Dubois, F. Rouaix, and P. Weis. Extensional polymorphism. In Twenty-Second ACM Symposium on Principles of Programming Languages, pages 118-129, San Francisco, Jan. 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 4.J.-Y. Girard. Interpretation fonctionelle et elimination des coupures de l'arithmetique d'ordre superieur. PhD thesis, Universite Paris VII, 1972.Google ScholarGoogle Scholar
  5. 5.J. Gosling, B. Joy, and G. Steele. The Java Language Speci~cation. Addison-Wesley, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 6.R. Harper and G. Morrisett. Compiling polymorphism using intensional type analysis. In Twenty-Second ACM Symposium on Principles of Programming Languages, pages 130-141, San Francisco, Jan. 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 7.F. Henglein. Dynamic typing. In B. Krieg-Br? uckner, editor, Fourth European Symposium on Programming, number 582 in Lecture Notes in Computer Science, pages 233-253. Springer-Verlag, Feb. 1992. Google ScholarGoogle Scholar
  8. 8.M. P. Jones. A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of Functional Programming, 5(1), Jan. 1995.Google ScholarGoogle ScholarCross RefCross Ref
  9. 9.X. Leroy and M. Mauny. Dynamics in ML. In J. Hughes, editor, Functional Programming Languages and Computer Architecture, number 523 in Lecture Notes in Computer Science, pages 406-426. Springer-Verlag, Aug. 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 10.R. Milner, M. Tofte, R. Harper, and D. MacQueen. The De~nition of Standard ML(Revised). TheMIT Press, Cambridge, Massachusetts, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 11.Y. Minamide, G. Morrisett, and R. Harper. Typed closure conversion. In Twenty-Third ACM Symposium on Principles of Programming Languages, pages 271{283, St. Petersburg, Florida, Jan. 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 12.J. C. Mitchell and G. D. Plotkin. Abstract types have existential type. ACM Transactions on Programming Languages and Systems, 10(3):470{502, July 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 13.S. Peyton Jones and J. Hughes (editors). Report on the programming language Haskell 98, a non-strict purely functional language. Technical Report YALEU/DCS/RR-1106, Yale University, Department of Computer Science, Feb. 1999. Available from http://www.haskell.org/definition/.Google ScholarGoogle Scholar
  14. 14.J. C. Reynolds. Towards a theory of type structure. In Programming Symposium, volume 19 of Lecture Notes in Computer Science, pages 408-425, 1974. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 15.P. Wadler. Theorems for free! In Fourth Conference on Functional Programming Languages and Computer Architecture, London, Sept. 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 16.P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad-hoc. In Sixteenth ACM Symposium on Principles of Programming Languages, pages 60-76. ACM, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. 17.S. Weeks. NJ PearLS dynamically extensible data structures in Standard ML. Talk presented at New Jersey Programming Languages and Systems Seminar, Sept. 1998. Transparencies available at http://www.star-lab.com/sweeks/talks.html. 65Google ScholarGoogle Scholar

Index Terms

  1. Type-safe cast: (functional pearl)

                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 '00: Proceedings of the fifth ACM SIGPLAN international conference on Functional programming
                  September 2000
                  294 pages
                  ISBN:1581132026
                  DOI:10.1145/351240

                  Copyright © 2000 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: 1 September 2000

                  Permissions

                  Request permissions about this article.

                  Request Permissions

                  Check for updates

                  Qualifiers

                  • Article

                  Acceptance Rates

                  ICFP '00 Paper Acceptance Rate24of110submissions,22%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