## Encoding types in ML-like languages (1998)

### Cached

### Download Links

- [repository.readscheme.org]
- [www.brics.dk]
- DBLP

### Other Repositories/Bibliography

Citations: | 42 - 0 self |

### BibTeX

@MISC{Yang98encodingtypes,

author = {Zhe Yang},

title = {Encoding types in ML-like languages},

year = {1998}

}

### Years of Citing Articles

### OpenURL

### Abstract

A Hindley-Milner type system such as ML's seems to prohibit type-indexed values, i.e., functions that map a family of types to a family of values. Such functions generally perform case analysis on the input types and return values of possibly different types. The goal of our work is to demonstrate how to program with type-indexed values within a Hindley-Milner type system. Our first approach is to interpret an input type as its corresponding value, recursively. This solution is type-safe, in the sense that the ML type system statically prevents any mismatch between the input type and function arguments that depend on this type. Such specific type interpretations, however, prevent us from combining different type-indexed values that share the same type. To meet this objection, we focus on finding a value-independent type encoding that can be shared by different functions. We propose and compare two solutions. One requires first-class and higher-order polymorphism, and, thus, is not implementable in the core language of ML, but it can be programmed using higher-order functors in Standard ML of New Jersey. Its usage, however, is clumsy. The other approach uses embedding/projection functions. It appears to be more practical. We demonstrate the usefulness of type-indexed values through examples including type-directed partial evaluation, C printf-like formatting, and subtype coercions. Finally, we discuss the tradeoffs between our approach and some other solutions based on more expressive typing disciplines.

### Citations

936 | A theory of type polymorphism in progra.mming
- Milner
- 1978
(Show Context)
Citation Context .... Finally, we discuss the tradeoffs between our approach and some other solutions based on more expressive typing disciplines. 1 Introduction Over the last two decades, the Hindley-Milner type system =-=[14, 20]-=- has been widely used. For example, it underlies several major statically typed functional programming languages, such as ML [21] and Haskell [24]. Among other This research was partially supported by... |

638 |
Partial evaluation and automatic program generation
- Jones, Gomard, et al.
- 1993
(Show Context)
Citation Context ...he lengthy tagging and untagging operations and the introduction of extra intermediate data structures. This problem can be overcome using program transformation techniques such as partial evaluation =-=[18]-=-, by specializing the general functions with respect to certain type encodings at compile time, and removing all the tagging/untagging operations. In particular, Danvy showed how it can be naturally c... |

604 |
The Definition of Standard ML (Revised
- Milner, Tofte, et al.
- 1990
(Show Context)
Citation Context ...oduction Over the last two decades, the Hindley-Milner type system [14, 20] has been widely used. For example, it underlies several major statically typed functional programming languages, such as ML =-=[21]-=- and Haskell [24]. Among other This research was partially supported by National Science Foundation grant CCR-9616993 and the Danish National Research Foundation. Part of this work was carried out dur... |

364 |
Towards a theory of type structure
- Reynolds
- 1974
(Show Context)
Citation Context ...Martin-Lofstyle encoding of inductive types using the corresponding elimination rules in System F! , which does support both first-class polymorphism and higher-order polymorphism in an explicit form =-=[10, 25]-=-. 4.2 Explicit first-class and higher-order polymorphism in SML/NJ The module system of Standard ML provides an explicit form of first-class polymorphism and higher-order polymorphism. Quantifying ove... |

259 | Compiling Polymorphism Using Intensional Type Analysis
- Harper, Morrisett
- 1995
(Show Context)
Citation Context ...lines give extra power, as shown in applications such as meta-programming and higher-level data/code transferring in distributed programming. 5.1.2 Intensional type analysis Intensional type analysis =-=[12]-=- directly supports type-indexed values in the languagesML i in order to compile polymorphism into efficient unboxed representations. The language ML i extends a predicative variant of Girard's System ... |

207 | Type-directed partial evaluation
- Danvy
(Show Context)
Citation Context ...fit into our canonical form of type-indexed values; however, pairing the two functions at each type index puts the definition into the standard form of a type-indexed value (Figure 3). In his article =-=[5]-=-, Danvy presents the Scheme code for this algorithm, where the type index is encoded as a value, thus reducing type analysis to case analysis. However, a direct transcription of that program into an M... |

195 | Standard ml of new jersey
- Appel, MacQueen
- 1991
(Show Context)
Citation Context ...-style encoding of inductive types. The encoding uses first-class polymorphism and higher-order polymorphism, and can be implemented using the higherorder module language of Standard ML of New Jersey =-=[3]. 2.-=- A type is encoded as the embedding and projection functions between verbatim values of that type and tagged values of a universal datatype. To encode a specific value v�� of a type-indexed value ... |

185 | A modal analysis of staged computation
- Davies, Pfenning
(Show Context)
Citation Context ...s to defer the type inference of some expressions until run-time when all related information is available. In particular, this approach is naturally combined with the framework of staged computation =-=[9, 30]-=- to support type-safe code generation at run-time. Staged programming helped to solve some of the original problems of dynamic typing, especially those concerning usages. However, the way type errors ... |

178 | A system of constructor classes: overloading and implicit higher-order polymorphism
- Jones
- 1993
(Show Context)
Citation Context ... such as allowing selective annotations of -bound variables with polymorphic types [23] or packaging of these variables using polymorphic datatype components [16]. Moreover, higher-order polymorphism =-=[15]-=- is needed to allow parameterizing over a type constructor, e.g., the type constructor obj. In fact, such type encodings are similar to a Martin-Lofstyle encoding of inductive types using the correspo... |

154 | Dynamic typing in a statically typed language
- Abadi, Cardelli, et al.
- 1991
(Show Context)
Citation Context ...reflect e = fn v1 =? reflect2 (APP(e, reify1(v1))) in (reify, reflect) end fun reify (T as (reifyT, reflectT)) v = reifyT v Figure 4: Type-directed partial evaluation in ML flatten (List (List Int)) [=-=[1, 2], [], [3], [4-=-, 5]] evaluates to [1,2,3,4,5]. We apply the same method to program type-directed partial evaluation (Figure 4) using the type interpretation [[�� ]] = (#; ") �� defined in Figure 3. As a... |

142 |
The principal type-scheme of an object in combinatory logic
- Hindley
- 1969
(Show Context)
Citation Context .... Finally, we discuss the tradeoffs between our approach and some other solutions based on more expressive typing disciplines. 1 Introduction Over the last two decades, the Hindley-Milner type system =-=[14, 20]-=- has been widely used. For example, it underlies several major statically typed functional programming languages, such as ML [21] and Haskell [24]. Among other This research was partially supported by... |

141 |
The system F of variable types, fifteen years later. Theoretical Computer Science 45
- Girard
- 1986
(Show Context)
Citation Context ...Martin-Lofstyle encoding of inductive types using the corresponding elimination rules in System F! , which does support both first-class polymorphism and higher-order polymorphism in an explicit form =-=[10, 25]-=-. 4.2 Explicit first-class and higher-order polymorphism in SML/NJ The module system of Standard ML provides an explicit form of first-class polymorphism and higher-order polymorphism. Quantifying ove... |

122 | Type classes in Haskell
- Hall, Hammond, et al.
- 1996
(Show Context)
Citation Context ... inconvenient to directly program in this language. Not surprisingly, the language ML i is mainly used as a typed-intermediate language. 5.1.3 Haskell type classes The type-class mechanism in Haskell =-=[11]-=- also makes it easy to program type-indexed values: the declaration of a type class should include all the type-indexed value needed, and every value construction e i should be implemented as an insta... |

97 | Dynamic Typing in Polymorphic Languages
- Abadi, Cardelli, et al.
- 1992
(Show Context)
Citation Context ...reflect e = fn v1 =? reflect2 (APP(e, reify1(v1))) in (reify, reflect) end fun reify (T as (reifyT, reflectT)) v = reifyT v Figure 4: Type-directed partial evaluation in ML flatten (List (List Int)) [=-=[1, 2], [], [3], [4-=-, 5]] evaluates to [1,2,3,4,5]. We apply the same method to program type-directed partial evaluation (Figure 4) using the type interpretation [[�� ]] = (#; ") �� defined in Figure 3. As a... |

95 | Putting type annotations to work
- Odersky, Laufer
- 1996
(Show Context)
Citation Context ...ws nested quantified types, as used in the type of argument func v. Substantial work has been done in this direction, such as allowing selective annotations of -bound variables with polymorphic types =-=[23]-=- or packaging of these variables using polymorphic datatype components [16]. Moreover, higher-order polymorphism [15] is needed to allow parameterizing over a type constructor, e.g., the type construc... |

71 |
Coercion and type inference
- Mitchell
- 1984
(Show Context)
Citation Context ...ng/projection-based approach can be readily applied to implementing values indexed by more than one type indices. Here let us take the example of writing an ML function that performs subtype coercion =-=[22]-=-. Given a from-type, a to-type, a list of subtype coercions at base types, and a value of the from-type, this function coerces the value to the to-type and return it. Following the general pattern, we... |

48 |
Dynamic typing: Syntax and proof theory
- Henglein
- 1994
(Show Context)
Citation Context ...d be defined in terms of proj �� i and emb �� i , respectively. More involved cases of embedding and projection functions between special types and universal tagged datatypes are studied in de=-=tail in [13]-=-. 4.3.1 Examples Taking the family F int;list of types, we can encode the type constructors as: datatype typeExpL = tInt --- tLst of typeExpL val Int = (fn x =? INT x, fn (INT x) =? x, tInt) fun List ... |

47 | First-class polymorphism with type inference
- Jones
- 1997
(Show Context)
Citation Context ...tial work has been done in this direction, such as allowing selective annotations of -bound variables with polymorphic types [23] or packaging of these variables using polymorphic datatype components =-=[16]-=-. Moreover, higher-order polymorphism [15] is needed to allow parameterizing over a type constructor, e.g., the type constructor obj. In fact, such type encodings are similar to a Martin-Lofstyle enco... |

40 | Report on the programming language haskell: A non-strict, purely functional language
- Fasel, Hammond, et al.
- 1992
(Show Context)
Citation Context ... last two decades, the Hindley-Milner type system [14, 20] has been widely used. For example, it underlies several major statically typed functional programming languages, such as ML [21] and Haskell =-=[24]-=-. Among other This research was partially supported by National Science Foundation grant CCR-9616993 and the Danish National Research Foundation. Part of this work was carried out during a visit to th... |

38 | Dynamic typing as staged type inference - Shields, Sheard, et al. - 1998 |

30 | Principal signatures for higher-order program modules - Tofte - 1992 |

25 | Relational parametricity and units of measure
- Kennedy
- 1997
(Show Context)
Citation Context ...n, this approach can be combined with type-directed partial evaluation to obtain 2-level functions, as done by Danvy for coercion functions and by Vestergaard for "`a la Kennedy" conversion =-=functions [19, 32]-=-. 5 Related work 5.1 Using more expressive type systems The problem of programming type-indexed values in a statically typed language like ML motivated several earlier works that introduce new feature... |

21 | Resource-aware programming - Taha - 2004 |

18 | The De nition of Standard ML (Revised - Milner, Tofte, et al. - 1997 |

14 | The system F of variable types, fteen years later - Girard - 1986 |

7 | From proof normalization to compiler generation and type-directed change-of-representation - Vestergaard - 1997 |

3 | A study in higher-order programming languages. Master 's thesis - Rhiger - 1997 |

2 |
Formatting strings in ML. Research Series RS-98-5, BRICS
- Danvy
- 1998
(Show Context)
Citation Context ... gives a type-safe solution to the problem. Based on our approach to type encodings, examples ranging from a printf-like formatting function 1 to type-directed par1 Initially devised by Olivier Danvy =-=[6]. A family of types �� Corresponding values v�-=-��� : T�� ��1 �� 2 types �� to a family of values v�� of types T�� . A type-indexed value v is a function mapping a family of v�� 1 : T�� 1 v�� 2 : T�� 2 v�... |

2 |
A simple solution to type specialization. Research Series RS-98-1, BRICS
- Danvy
- 1998
(Show Context)
Citation Context ... the embedding function emb, then, the resulting tagged expression must comply with the type expression tE. This value-independent type encoding can be used for the `type specialization' described in =-=[7]-=-, where the partial evaluator and the projection function are type-indexed by the same family of types. 4.3.2 Comments Finally, we briefly argue that the above approach based on embedding and projecti... |

2 | Type-directed partial evaluation in a pure functional language - Rose |