Multiple Values in Standard ML

Kevin Mitchell

Abstract: ML has traditionally used pairs, tuples or currying to handle functions requiring more than one argument. Tuples are also used when a function needs to return multiple results. Compilers must then take care to optimise function calls if the resulting programs are to achieve a performance comparable to languages that support multiple arguments and results. In this paper we argue that it is difficult for a compiler to do this job entirely satisfactorily because the intended pattern of usage of a function is usually unknown at the time it is declared. We argue for the introduction of sequences into the language. Each expression evaluates to a sequence of values. Such sequences are not values and so cannot be bound to a variable. They can however be bound to a sequence of variables or, more generally, patterns of the same length. We demonstrate how this change can allow the programmer to help the compiler generate more efficient code. We also use this extension to justify an optimisation used by a number of ML compilers.

LFCS report ECS-LFCS-94-312, December 1994. (0.9Mb PostScript file)

Previous | Index | Next