Type-FUNCTIONAL PEARL safe cast

  • Authors:
  • Stephanie Weirich

  • Affiliations:
  • University of Pennsylvania, Philadelphia, PA 19104, USA (email: sweirich@cis.upenn.edu)

  • Venue:
  • Journal of Functional Programming
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Comparing two types for equality is an essential ingredient for an implementation of dynamic types. Once equality has been established, it is safe to cast a value from one type to another. In a language with run-time type analysis, implementing such a procedure is fairly straightforward. Unfortunately, this naive implementation destructs and rebuilds the argument while iterating over its type structure. However, by using higher-order polymorphism, a casting function can treat its argument parametrically. We demonstrate this solution in two frameworks for ad-hoc polymorphism: intensional type analysis and Haskell type classes.