Type-safe cast

被引:10
作者
Weirich, S [1 ]
机构
[1] Univ Penn, Philadelphia, PA 19104 USA
关键词
D O I
10.1017/S0956796804005179
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:681 / 695
页数:15
相关论文
共 14 条
[1]   DYNAMIC TYPING IN A STATICALLY TYPED LANGUAGE [J].
ABADI, M ;
CARDELLI, L ;
PIERCE, B ;
PLOTKIN, G .
ACM TRANSACTIONS ON PROGRAMMING LANGUAGES AND SYSTEMS, 1991, 13 (02) :237-268
[2]  
[Anonymous], 2003, Haskell 98 Language and LibrariesThe Revised Report
[3]  
BAAAS A, 2002, 2002 ACM INT C FUNCT, P157
[4]  
Cheney J., 2002, P 2002 ACM SIGPLAN W, P90, DOI DOI 10.1145/581690.581698
[5]  
GOSLING J, 1996, JAVA LANGUAGE SPECIF
[6]  
HARPER R, 1995, 22 ACM S PRINC PROGR, P130
[7]  
HENGLEIN F, 1992, LECT NOTES COMPUT SC, V582, P233
[8]  
JONES MP, 1995, J FUNCT PROGRAM, V5
[9]  
LEROY X, 1991, LECT NOTES COMPUT SC, V523, P406
[10]  
Minamide Yasuhiko, 1996, S PRINC PROGR LANG P, P271, DOI DOI 10.1145/237721.237791