Type-safe cast: (functional pearl)

  • Authors:
  • Stephanie Weirich

  • Affiliations:
  • Department of Computer Science, Cornell University, Ithaca, NY

  • Venue:
  • ICFP '00 Proceedings of the fifth ACM SIGPLAN international conference on Functional programming
  • Year:
  • 2000

Quantified Score

Hi-index 0.00

Visualization

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.