Embedding polymorphic dynamic typing

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.

[1]  Simon L. Peyton Jones,et al.  Type checking with open type functions , 2008, ICFP.

[2]  Manuel M. T. Chakravarty,et al.  Plugging Haskell in , 2004, Haskell '04.

[3]  Conor McBride First-order unification by structural recursion , 2003, J. Funct. Program..

[4]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[5]  Ulf Norell,et al.  Dependently typed programming in Agda , 2009, TLDI '09.

[6]  Martín Abadi,et al.  Dynamic typing in polymorphic languages , 1995, Journal of Functional Programming.

[7]  Martín Abadi,et al.  Dynamic typing in a statically-typed language , 1989, POPL '89.

[8]  Marinus J. Plasmeijer,et al.  A Functional Shell That Operates on Typed and Compiled Applications , 2004, Advanced Functional Programming.

[9]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[10]  Emir Pasalic,et al.  Meta-programming With Built-in Type Equality , 2008, Electron. Notes Theor. Comput. Sci..

[11]  Xavier Leroy,et al.  Dynamics in ML , 1991, FPCA.

[12]  Marinus J. Plasmeijer,et al.  Ad-hoc polymorphism and dynamic typing in a statically typed functional language , 2010, WGP '10.

[13]  Robert Atkey,et al.  Unembedding domain-specific languages , 2009, Haskell.

[14]  David Walker,et al.  Dynamic Typing with Dependent Types , 2004, IFIP TCS.

[15]  Wouter Swierstra,et al.  The power of Pi , 2008, ICFP.

[16]  Karl Crary,et al.  Flexible type analysis , 1999, ICFP '99.

[17]  James Cheney,et al.  A lightweight implementation of generics and dynamics , 2002, Haskell '02.

[18]  Thorsten Altenkirch,et al.  Generic Programming within Dependently Typed Programming , 2002, Generic Programming.

[19]  Don Stewart,et al.  Dynamic extension of typed functional languages , 2010 .

[20]  Bas Lijnse,et al.  iTasks for a change: type-safe run-time change in dynamically evolving workflows , 2011, PEPM '11.

[21]  de Ng Dick Bruijn Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem , 1972 .

[22]  Emir Pasalic,et al.  Meta-programming with Typed Object-Language Representations , 2004, GPCE.

[23]  Marco Pil First Class File I/O , 1996, Implementation of Functional Languages.

[24]  S. Doaitse Swierstra,et al.  Typing dynamic typing , 2002, ICFP '02.

[25]  de Ng Dick Bruijn,et al.  Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem , 1972 .

[26]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.