FUNCTIONAL PEARL Type-safe cast
Published online by Cambridge University Press: 27 October 2004
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.
- Type
- Functional pearls
- Information
- Copyright
- © 2004 Cambridge University Press
Footnotes
- 12
- Cited by
Discussions
No Discussions have been published for this article.