Encoding types in ML-like languages

This article presents several general approaches to programming with type-indexed families of values within a Hindley-Milner type system. A type-indexed family of values is a function that maps a family of types to a family of values. The function performs a case analysis on the input types and returns values of possibly different types. Such a case analysis on types seems to be prohibited by the Hindley-Milner type system. Our approaches solve the problem by using type encodings. The compile-time types of the type encodings reflect the types themselves, thereby making the approaches type-safe, in the sense that the underlying type system statically prevents any mismatch between the input type and the function arguments that depend on this type.A type encoding could be either value-dependent, meaning that the type encoding is tied to a specific type-indexed family, or value-independent, meaning that the type encoding can be shared by various type-indexed families. Our first approach is value-dependent: we simply interpret a type as its corresponding value. Our second approach provides value-independent type encodings through embedding and projection functions; they are universal type interpretations, in that they can be used to compute other type interpretations. We also present an alternative approach to value-independent type encodings, using higher-order functors.We demonstrate our techniques through applications such as C printf-like formatting, type-directed partial evaluation, and subtype coercions.

[1]  Fritz Henglein Dynamic Typing , 1992, ESOP.

[2]  Robin Milner,et al.  Definition of standard ML , 1990 .

[3]  Mads Tofte Principal Signatures for Higher-Order Program Modules , 1994, J. Funct. Program..

[4]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[5]  John Hughes,et al.  The Design of a Pretty-printing Library , 1995, Advanced Functional Programming.

[6]  Olivier Danvy,et al.  Type-directed partial evaluation , 1995, POPL '96.

[7]  Fritz Henglein,et al.  Dynamic Typing: Syntax and Proof Theory , 1994, Sci. Comput. Program..

[8]  Simon L. Peyton Jones,et al.  Type classes in Haskell , 1994, TOPL.

[9]  R. Hindley The Principal Type-Scheme of an Object in Combinatory Logic , 1969 .

[10]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[11]  Harold Abelson,et al.  Revised5 report on the algorithmic language scheme , 1998, SIGP.

[12]  Andrew Kennedy,et al.  Relational parametricity and units of measure , 1997, POPL '97.

[13]  Robert Harper,et al.  Compiling polymorphism using intensional type analysis , 1995, POPL '95.

[14]  Sophia Mã ¶ ller Partial Evaluation Practice And Theory Diku 1998 International Summer School Copenhagen Denmark June 29 July 10 1998 , 1998 .

[15]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[16]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[17]  Walid Taha,et al.  Multi-stage programming (poster) , 1997, ICFP '97.

[18]  Olivier Danvy Functional Unparsing , 1998, J. Funct. Program..

[19]  Simon L. Peyton Jones,et al.  Dynamic typing as staged type inference , 1998, POPL '98.

[20]  Jean-Yves Girard,et al.  The System F of Variable Types, Fifteen Years Later , 1986, Theor. Comput. Sci..

[21]  Martin Odersky,et al.  Putting type annotations to work , 1996, POPL '96.

[22]  Martín Abadi,et al.  Dynamic typing in polymorphic languages , 1995, Journal of Functional Programming.

[23]  Mark P. Jones,et al.  A system of constructor classes: overloading and implicit higher-order polymorphism , 1993, FPCA '93.

[24]  Olivier Danvy A Simple Solution to Type Specialization , 1998 .

[25]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[26]  Mark P. Jones,et al.  First-class polymorphism with type inference , 1997, POPL '97.

[27]  John C. Mitchell,et al.  Coercion and type inference , 1984, POPL.

[28]  Morten Rhiger A Study in Higher-Order Programming Languages , 1997 .

[29]  Johan Jeuring,et al.  PolyP—a polytypic programming language extension , 1997, POPL '97.

[30]  David B. MacQueen,et al.  The Definition of Standard ML (Revised) , 1997 .