Embedding polymorphic dynamic typing

  • Authors:
  • Thomas van Noort;Wouter Swierstra;Peter Achten;Rinus Plasmeijer

  • Affiliations:
  • Radboud University Nijmegen, Nijmegen, Netherlands;Radboud University Nijmegen, Nijmegen, Netherlands;Radboud University Nijmegen, Nijmegen, Netherlands;Radboud University Nijmegen, Nijmegen, Netherlands

  • Venue:
  • Proceedings of the seventh ACM SIGPLAN workshop on Generic programming
  • Year:
  • 2011

Quantified Score

Hi-index 0.00

Visualization

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.