skip to main content
10.1145/2036918.2036923acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Embedding polymorphic dynamic typing

Published: 18 September 2011 Publication History

Abstract

Dynamic typing in a statically typed functional language allows us to defer type unification until run time. This is typically useful when interacting with the 'outside' world where the type of values involved may not be known statically. Haskell has minimal support for dynamic typing, it only supports monomorphism. Clean, on the other hand, has a more rich and mature dynamic typing system where polymorphism is supported as well. An interesting difference is that Haskell offers monomorphic dynamic typing via a library, while Clean offers polymorphic dynamic typing via built-in language support. In the Clean approach there is a great deal of freedom in the implementation in the compiler since the dynamic typing system is defined on abstract syntax trees, whereas the Haskell approach does not need to extend the core language and hence reduces the complexity of the language and compiler. In this paper we investigate what it takes for a functional language to embed polymorphic dynamic typing. We explore an embedding in Haskell using generalised algebraic datatypes and argue that a universe for the representation of types needs to separated from its interpretation as a type. We motivate the need for a dependently-typed functional language like Agda and perform the embedding using structural equality on type representations. Finally, we extend this approach with an instance-of algorithm and define a framework for the corresponding cast function.

Supplementary Material

JPG File (_talk3.jpg)
MP4 File (_talk3.mp4)

References

[1]
Martín Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically typed language. ACM Transactions on Programming Languages and Systems, 13 (2): 237--268, 1991.
[2]
Martín Abadi, Luca Cardelli, Benjamin Pierce, Didier Rémy, and Robert Taylor. Dynamic typing in polymorphic languages. Journal of Functional Programming, 5 (1): 81--110, 1994.
[3]
Thorsten Altenkirch and Conor McBride. Generic programming within dependently typed programming. In Jeremy Gibbons and Johan Jeuring, editors, Proceedings of the IFIP TC2 Working Conference on Generic Programming, Dagstuhl, Germany, pages 1--20. Kluwer Academic Publishers, 2003.
[4]
Robert Atkey, Sam Lindley, and Jeremy Yallop. Unembedding domain-specific languages. In Stephanie Weirich, editor, Proceedings of the Haskell Symposium, Haskell '09, Edinburgh, UK, pages 37--48. ACM Press, 2009.
[5]
Arthur Baars and Doaitse Swierstra. Typing dynamic typing. In Simon Peyton Jones, editor, Proceedings of the International Conference on Functional Programming, ICFP '02, Pittsburgh, PA, USA, pages 157--166. ACM Press, 2002.
[6]
Nicolaas Bruijnde Bruijn. Lambda calculus notation with nameless dummies: A tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagaciones Mathematische, 34: 381--392, 1972.
[7]
James Cheney and Ralf Hinze. A lightweight implementation of generics and dynamics. In Manuel Chakravarty, editor, Proceedings of the Haskell Workshop, Haskell '02, Pittsburgh, PA, USA, pages 90--104. ACM Press, 2002.
[8]
Karl Crary and Stephanie Weirich. Flexible type analysis. In Didier Remy, editor, Proceedings of the International Conference on Functional Programming, ICFP '99, Paris, France, pages 233--248. ACM Press, 1999.
[9]
Xavier Leroy and Michel Mauny. Dynamics in ML. Journal of Functional Programming, 3 (4): 431--463, 1993.
[10]
Conor McBride. First-order unification by structural recursion. Journal of Functional Programming, 13 (6): 1061--1075, 2003.
[11]
Thomas van Noort, Peter Achten, and Rinus Plasmeijer. Ad-hoc polymorphism and dynamic typing in a statically typed functional language. In Bruno Oliveira and Marcin Zalewski, editors, Proceedings of the Workshop on Generic Programming, WGP '10, Baltimore, MD, USA, pages 73--84. ACM Press, 2010.
[12]
Ulf Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007.
[13]
Ulf Norell. Dependently typed programming in Agda. In Pieter Koopman, Rinus Plasmeijer, and Doaitse Swierstra, editors, Revised Lectures of the International Summer School on Advanced Functional Programming, AFP '08, Heijen, The Netherlands, volume 5832 of Lecture Notes in Computer Science, pages 230--266. Springer-Verlag, 2008.
[14]
Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and David Walker. Dynamic typing with dependent types. In Jean-Jacques Lévy, Ernst Mayr, and John Mitchell, editors, Proceedings of the International Conference on Theoretical Computer Science, TCS '04, Toulouse, France, pages 437--450. Kluwer Academic Publishers, 2004.
[15]
Nicolas Oury and Wouter Swierstra. The power of Pi. In James Hook and Peter Thiemann, editors, Proceedings of the International Conference on Functional Programming, ICFP '08, Victoria, BC, Canada, pages 39--50. ACM Press, 2008.
[16]
André Pang, Don Stewart, Sean Seefried, and Manuel Chakravarty. Plugging Haskell in. In Henrik Nilsson, editor, Proceedings of the Haskell Workshop, Haskell '04, Snowbird, UT, USA, pages 10--21. ACM Press, 2004.
[17]
Emir Pasalić and Nathan Linger. Meta-programming with typed object-language representations. In Gábor Karsai and Eelco Visser, editors, Proceedings of the International Conference on Generative Programming and Component Engineering, GPCE '04, Vancouver, BC, Canada, volume 3286 of Lecture Notes in Computer Science, pages 136--167. Springer-Verlag, 2004.
[18]
Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. Simple unification-based type inference for GADTs. In Julia Lawall, editor, Proceedings of the International Conference on Functional Programming, ICFP '06, Portland, OR, USA, pages 50--61. ACM Press, 2006.
[19]
Frank Pfenning and Conal Elliot. Higher-order abstract syntax. In Proceedings of the Conference on Programming Language Design and Implementation, PLDI '88, Atlanta, GA, USA, pages 199--208. ACM Press, 1988.
[20]
Marco Pil. First class file I/O. In Chris Clack, Kevin Hammond, and Antony Davie, editors, Selected Papers of the International Workshop on Implementation of Functional Languages, IFL '97, St. Andrews, UK, volume 1467 of Lecture Notes in Computer Science, pages 233--246. Springer-Verlag, 1997.
[21]
Rinus Plasmeijer and Arjen van Weelden. A functional shell that operates on typed and compiled applications. In Varmo Vene and Tarmo Uustalu, editors, Proceedings of the 5th International Summer School on Advanced Functional Programming, AFP '04, Tartu, Estonia, volume 3622 of Lecture Notes in Computer Science, pages 245--272. Springer-Verlag, 2005.
[22]
Rinus Plasmeijer, Peter Achten, Pieter Koopman, Bas Lijnse, Thomas van Noort, and John van Groningen. iTasks for a change - Type-safe run-time change in dynamically evolving workflows. In Siau-Cheng Khoo and Jeremy Siek, editors, Proceedings of the Workshop on Partial Evaluation and Program Manipulation, PEPM '11, Austin, TX, USA, pages 151--160. ACM Press, 2011.
[23]
Tom Schrijvers, Simon Peyton Jones, Manuel Chakravarty, and Martin Sulzmann. Type checking with open type functions. In Peter Thiemann and James Hook, editors, Proceedings of the International Conference on Functional Programming, ICFP '08, Victoria, BC, Canada, pages 51--62. ACM Press, 2008.
[24]
Tim Sheard and Emir Pasalić. Meta-programming with built-in type equality. Electronic Notes in Theoretical Computer Science, 199: 49--65, 2008.
[25]
Tim Sheard, James Hook, and Nathan Linger. GADTs + extensible kinds = dependent programming. Technical report, Portland State University, 2005.
[26]
Don Stewart. Dynamic extension of typed functional languages. PhD thesis, University of New South Wales, 2010.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
WGP '11: Proceedings of the seventh ACM SIGPLAN workshop on Generic programming
September 2011
102 pages
ISBN:9781450308618
DOI:10.1145/2036918
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: 18 September 2011

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. dependently-typed programming
  2. dynamic typing
  3. generalised algebraic datatypes
  4. instantiation
  5. polymorphism
  6. unification
  7. universe construction

Qualifiers

  • Research-article

Conference

ICFP '11
Sponsor:

Acceptance Rates

WGP '11 Paper Acceptance Rate 8 of 10 submissions, 80%;
Overall Acceptance Rate 30 of 43 submissions, 70%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 112
    Total Downloads
  • Downloads (Last 12 months)1
  • Downloads (Last 6 weeks)0
Reflects downloads up to 06 Jan 2025

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media